0

Why doesn’t work My Code in the Code challenge „Symbols“?

The Output of My Code is like it should be, but everything is marked wrong. My Code (C++): #include <iostream> #include <string> using namespace std; int main() { string eingabe; char a; getline(cin, eingabe); for (unsigned long int i = 1; i <= eingabe.length(); i++) { a = eingabe[i-1]; if (!((a >= 65 && a <= 90) || (a >= 97 && a <= 122) || (a == 32) || (a >= 48 && a <= 57))) { eingabe[i-1] = '\0'; } } cout << eingabe; return 0; } Thanks for your help.

14th Jan 2020, 9:42 PM
Mo1996
1 ответ
+ 1
I can't really answer this definitely because I don't how how SoloLearn does the retrieval and evaluation of your solution, but from experience I can tell you that using null characters as replacement does not work. My guess is that everything you send to the output buffer is evaluated, and since the null characters are being send along with the rest of the string, they are also part of the comparison to the given solution, which then obviously fails. You don't see any of this because the null-termination character has no visual representation and therefore the solution looks fine. Either way, null-termination characters are also evaluated when printed to the screen, so you will need to come up with another idea instead.
14th Jan 2020, 10:28 PM
Shadow
Shadow - avatar