0

C++

I am writing a program to convert special characters in the text to underscore. But the program is convert the whole text to single line. I am supposed to use ASCII values in this task. What could be the problem https://code.sololearn.com/cdLtmPw2RomD/?ref=app

3rd Dec 2020, 7:22 PM
Reynolds Onyango
Reynolds Onyango - avatar
3 ответов
+ 2
You can use `isalnum` function from <cctype> header. It is a function that returns true when given an alphanumeric value as argument. When non alphanumeric value was given as argument, the function returns false. #include <cctype> // for isalnum() for( unsigned int i = 0; i < strlen(text); i++) { if(!isalnum(text[i])) { text[i] = '_'; } } http://www.cplusplus.com/reference/cctype/isalnum/ (Edit) If you were restricted to use only ASCII values, then follow Szwendacz's advice.
3rd Dec 2020, 7:59 PM
Ipang
+ 1
missing parentheses for( unsigned int i = 0; i < strlen(text); i++) { if(!((text[i]>=48 && text[i]<=57)||(text[i]>=65 && text[i]<=90) || (text[i]>=97 && text[i]<=122))) { text[i] = '_'; } }
3rd Dec 2020, 7:29 PM
Szwendacz
Szwendacz - avatar
+ 1
Super thanks guys
3rd Dec 2020, 8:37 PM
Reynolds Onyango
Reynolds Onyango - avatar