+ 1

Wrong stringsizes printing. Why?

If you input cat, dog and rat into code, Stringsize output for cat and dog is 4, but for rat is 3 Why? Code: https://code.sololearn.com/caeYtyr8q9qS/?ref=app Thanks for advance

2nd Feb 2020, 3:45 PM
Veli-Matti
2 Antworten
+ 3
you can see here in second paragraph http://www.cplusplus.com/reference/cstdio/fgets/ `A newline character makes fgets stop reading, but it is considered a valid character by the function and included in the string copied to str.` you can prove it by check their last character and see if its \n or not
2nd Feb 2020, 4:15 PM
Taste
Taste - avatar
0
Thank you good sir!
2nd Feb 2020, 4:16 PM
Veli-Matti