(e-mail address removed) said:
Is there any efficcient way of removing the newline character from the
buffer read by
fgets() ?
Others here have posted sensible suggestions on the best way to remove the
newline character from the buffer after an fgets call. But if you're really
after efficiency, don't use fgets!
Is there any library function that is similar to fgets() but also tells
how many
bytes it read into the buffer ?
No such standard library function exists, but you could write a routine
yourself to do it. It could also have the following characteristics:
1) always reads a complete line (subject to available memory), by expanding
the buffer as and when necessary
2) allows you to re-use the same buffer over and over (like fgets)
3) records and reports the number of bytes read into the buffer per call
4) records and reports the current size of the buffer (*not* the same thing
as the length of the string contained therein)
5) doesn't bother putting a newline on the end, because there's no need,
because of Property 1, and therefore the caller need not remove it
Such a routine is far, far, far simpler to write than you might imagine.