[cs631apue] reading from stdin

kthompso kthompso at stevens.edu
Fri Dec 2 12:34:32 EST 2016


> Should we use fgets to read from stdin or will the read system be okay?

I would not use fgets(3) to read in the data.  From the documentation:

> char *fgets(char *s, int size, FILE *stream);
> 
> fgets() reads in at most one less than size characters from stream and
> stores them into the buffer pointed to by s. Reading stops after an EOF
> or a newline. If a newline is read, it is stored into the buffer. A
> terminating null byte (aq\0aq) is stored after the last character in
> the buffer.

You basically don't want _any_ of that functionality, especially the 
part
where it modifies incoming data.  You would be better off using read(2)
with the stdin file descriptor.

-Kyle


More information about the cs631apue mailing list