[cs631apue] reading from stdin
mseaton
mseaton at stevens.edu
Fri Dec 2 22:13:34 EST 2016
Thank you Kyle.
Marlon
On 12/02/2016 12:34 PM, kthompso wrote:
>> 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
> _______________________________________________
> cs631apue mailing list
> cs631apue at lists.stevens.edu
> https://lists.stevens.edu/mailman/listinfo/cs631apue
More information about the cs631apue
mailing list