0
the spy life test ( fails test case 5)
this is my code for the challenge the spy life test . My code is passing 4 cases out of 5. I don't know what the problem is . could you help me with this . the code was written with c++. https://code.sololearn.com/cJTaK33K8w7F/#cpp #include <iostream> #include <string> using namespace std; int main () { string input ; char temp [30] ; int j = 0; getline (cin, input); for(int i =0 ; input[i];i++){ if((input[i]>='a'&& input[i]<='z')||(input[i]>='A'&&input[i]<='Z')|| (input[i]==' ')){ temp[j++]=input[i]; } } char output [j]; for (int i = 0 ; i <=j/2 ; i ++){ output [i] = temp [j-i-1]; output [j-i-1] = temp [i]; } output [j]=' '; cout << output ; return 0 ; }
3 ответов
+ 3
Line 21
output[j] = '\0';
...seems to solve your problem...
+ 1
It seems you forgot to add the null character to your char strings!
0
Try to learn STL for better understanding of the problem. https://code.sololearn.com/cvv4i17S3MFT/?ref=app