> But, Salem (or anybody who can answer that), can you still explain my question about fgets and looping like that?
> So, for every iteration, it's going to read a new line every time, right?
It will read the next 20 chars on the current line, and will keep doing that until it finds one of the buffers which contains the newline (in which case, fgets() will return before the buffer is full).
It doesn't throw the rest of the line away just because it could not fit the line into the current buffer - it just returns a full buffer and hopes you will deal with that before calling fgets again.
Newline is just a convenient place to stop.
It's also not gets(), which will roam all through memory writing junk until it sees a newline, and nothing is going to get in its way until it sees that newline.
And Quzah's code calls strlen with a NULL pointer.
And Sebastiani's C++ code wont work with stdin.