This is a discussion on Scanning new line within the C Programming forums, part of the General Programming Boards category; Originally Posted by laserlight
Yep. Why not just make length a size_t?
I didn't know what size_t represented until now, ...
I didn't know what size_t represented until now, and we haven't used it in class yet.
Originally Posted by laserlight
Also, note that if you are replacing the last character of a string with a null character, then you have effectively reduced the length by 1. Thus, if you want to use the length variable later on, then for correctness you should subtract 1 from it too, hence the decrement in my example in post #21. In your case, you are writing it in a function that will not use length afterwards, so it is arguably okay.
Yes I understand that. This code is in a void function right now so I could have added the int return, but I haven't found a reason to need the string length of the user input.