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 ; }

8th Aug 2021, 8:59 PM
Arman Tahery
Arman Tahery - avatar
3 Respuestas
+ 3
Line 21 output[j] = '\0'; ...seems to solve your problem...
8th Aug 2021, 9:55 PM
Jan
Jan - avatar
+ 1
It seems you forgot to add the null character to your char strings!
8th Aug 2021, 9:28 PM
Jan
Jan - avatar
0
Try to learn STL for better understanding of the problem. https://code.sololearn.com/cvv4i17S3MFT/?ref=app
8th Aug 2021, 9:33 PM
Samia Haque
Samia Haque - avatar