0
Whats wrong with this code?👇👇👇
#include <iostream> using namespace std; #include <stdio.h> #include <string.h> int main() { char forward[] = "This is my string!"; char backward[strlen(forward)] = ""; int j = 0; for(int i = strlen(forward); i >= 0; --i){ backward[j] += forward[i]; cout << backward[j]; j++; } return 0; }
4 odpowiedzi
0
Whats wrong you getting..?
Specify that pls...
0
Why isn't the code running?
0
It's perfectly running for me..
Try again..
Save the code in playground and share link here, If any problem still...
Edit :
It's running but your accessing an extra out of string bounds character. It returning a space, not visible clearly but it us there.. So add as specified below by @Vasile Eftodii.. As i=strlen(forword) - 1;
0
You need to initialize the counter correctly:
for (int i = strlen(forward) - 1; i >= 0; i--) {...}
http://www.cplusplus.com/reference/cstring/strlen/