C Code returning random characters at end. | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

C Code returning random characters at end.

After I print out the final output it returns a random string of characters. The code takes in an input that is replaced with a flipped alphabet version of the text. https://code.sololearn.com/cXgYh7bpYRN6/#c

21st Oct 2020, 10:22 PM
Cloregaming
Cloregaming - avatar
2 Answers
+ 6
You can add output[i] = '\0'; After your loop to correct the issue. It's printing out the garbage values left behind in those memory locations, since it doesn't see the termination of the C string.
21st Oct 2020, 10:55 PM
ChaoticDawg
ChaoticDawg - avatar
+ 3
You forgot to terminate the string, i.e., forgot to add '\0' at the end of the string. So printf() has no idea until when to stop printing the string.
21st Oct 2020, 10:46 PM
你知道規則,我也是
你知道規則,我也是 - avatar