0

Why the strrev[i] = '\0' null in the end of the code?

https://code.sololearn.com/csJ1sY4LSGI4/?ref=app Code is from https://www.tutorialgateway.org/c-program-to-reverse-a-string/ Not my own code, but all many thanks to them from tutorials.

1st Feb 2020, 4:40 PM
Veli-Matti
4 Antworten
+ 4
Anmol Kumar I'm don't know much about C but I'm not sure... If I comment out that line i get the same output. Veli-Matti strrev is a function. Use another variable name to avoid error in other compilers. https://www.sololearn.com/discuss/2149972/?ref=app
1st Feb 2020, 6:04 PM
Kevin ★
+ 1
Well, strlen function doesn't include null character ('\0') while counting the characters in your string, so we've to explicitly tell the compiler about the null character by doing strrev[i] = '\0'
1st Feb 2020, 5:22 PM
Anmol Kumar
Anmol Kumar - avatar
0
Thank you very much!
1st Feb 2020, 5:39 PM
Veli-Matti
0
Strrev didnt work in sololearn last time I tried. Some say its not a standard function. But Ty for the tip!
1st Feb 2020, 6:06 PM
Veli-Matti