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

16th Oct 2020, 12:35 PM
Amal Gil
Amal Gil - avatar
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.
16th Oct 2020, 1:04 PM
HARITEJA KODURI
HARITEJA KODURI - avatar
+ 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.
16th Oct 2020, 1:16 PM
Zerokles
Zerokles - avatar
+ 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/
16th Oct 2020, 1:19 PM
Ipang
+ 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.
16th Oct 2020, 10:00 PM
Zerokles
Zerokles - avatar
+ 1
Now your indice Variable giving warning un-used variable because you have not used this variable in program. Make it comment.
16th Oct 2020, 3:22 PM
A S Raghuvanshi
A S Raghuvanshi - avatar
+ 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.
16th Oct 2020, 3:53 PM
Amal Gil
Amal Gil - avatar
0
Martin Taylor Yes the fonction isalnum but whethever it encounters a space it stops reading the author characters.
16th Oct 2020, 8:32 PM
Amal Gil
Amal Gil - avatar