Whats wrong with this code?👇👇👇 | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
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; }

19th Jul 2020, 11:10 AM
Abraham Zimba
Abraham Zimba - avatar
4 Answers
0
Whats wrong you getting..? Specify that pls...
19th Jul 2020, 11:16 AM
Jayakrishna 🇮🇳
0
Why isn't the code running?
19th Jul 2020, 11:17 AM
Abraham Zimba
Abraham Zimba - avatar
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;
19th Jul 2020, 11:19 AM
Jayakrishna 🇮🇳
0
You need to initialize the counter correctly: for (int i = strlen(forward) - 1; i >= 0; i--) {...} http://www.cplusplus.com/reference/cstring/strlen/
19th Jul 2020, 11:51 AM
Vasile Eftodii
Vasile Eftodii - avatar