0
Whatcis the error in my code please
I want to print only the characters and the number in a given string https://code.sololearn.com/c9zTX0slAzDb/?ref=app
9 Answers
+ 2
At line 9 'a-z' and '0-9' I think you want them as regular expressions. But c takes them as strings. Everything in ' ' are taken as strings in c.
If you want to rectify:-
Method1:-
There is a std library called regex.h it will do regular expressions suff.
Method2:-
If you think regular expressions is hard. create array including all strings and integers in it and verify while iterationg through it.
Method3:-
Create a string with all these characters and verify while iterating through this string.
+ 2
You can use the isalnum() function to check if a character is alphanumeric.
It's defined in the <ctype.h> header file.
Edit: Thank you Martin Taylor. Yes it's isalnum(). Fixed it.
+ 2
You can include <ctype.h> and use `isalpha` for checking alphabets , and `isdigit` for checking digits.
http://www.cplusplus.com/reference/cctype/isalpha/
http://www.cplusplus.com/reference/cctype/isdigit/
+ 2
amal 01
When it comes to reading a line of input with spaces, you can use the fgets() function. Syntax is as follows:
fgets(str, 50, stdin);
Martin's suggestion probably works too. I haven't learned that syntax yet lol.
+ 1
Now your indice Variable giving warning un-used variable because you have not used this variable in program. Make it comment.
+ 1
â¨ď¸TEJAS MK-82â¨ď¸
I don't think so even if I removed the indice variable.
The problem is that 'i' when it encounters space it stop reading other characters.
So I have to write a program that even if there is a space it will continue reading the string.
0
Martin Taylor
Yes the fonction isalnum but whethever it encounters a space it stops reading the author characters.