Originally Posted by
Barney McGrew
I've provided two examples in which gets is used. The program knows the exact number of characters that are on stdin preceding the new line in both cases, so there is absolutely zero harm in using it in both of those cases. A size parameter is unnecessary in both of the examples I've provided, just as it's unnecessary when you can verify that the destination buffer is large enough to store the source string in a call to strcpy. You shouldn't use gets when it introduces bugs in your programs, but that is not always the case, as I've already demonstrated.Although, there is one reason for why you should avoid the use of gets entirely, and that's because it's no longer part of the standard C library.edit: If you can come up with another reason (independent of the context in which it's used), then I'd like to hear it. Otherwise you'd just be repeating what I've said.