+ 2
Please help in the code coach challenge?
I have got a mistake in symbols code coach challenge and the mistake is in #4. Please help me to solve this problem using C https://code.sololearn.com/cvhbCwKGAB4t/?ref=app
3 odpowiedzi
+ 3
Since you don't copy the null character over to "copy", you need to null-initialize the string, otherwise puts() will continue writing characters until it finds a random null character in memory, which might or might not be at the end of the string. Simply change the initialization to
char sentence[ 100 ] = {}, copy[ 100 ] = {};
and the solution will be fine.
Two notes:
The code is written in C, not C# - you might want to edit your question/ tags to that effect.
Also, it is advised to avoid gets() in favor of either scanf() or fgets():
https://stackoverflow.com/questions/1694036/why-is-the-gets-function-so-dangerous-that-it-should-not-be-used
0
copy[k]='\0';
Just append a null to char array just after the loop
0
You don't actually need copy[100], if the condition is satisfied, print it out. You can also use isalnum() instead of isalpha & isdigit together.