Substitute for gets()

MJSchmelzer xmjschm at hscfvax.harvard.edu
Thu Feb 9 10:29:38 AEST 1989


Thanks to everyone who suggested using fgets() instead of gets().
(There, that was my summary of all the answers mailed to me.)

fgets() hadn't even occurred to me because I naively assumed it was like
fscanf() and fprint() in that it only differed by adding a stream
parameter.
   Fortunately, fgets() takes 3 parameters, including the all-important
buffer-size parameter. Here is the prototype (K&R2, p. 165):

char * fgets(char * s, int n, FILE * iop);

One final question: No one mentioned scanf("%255s", buffer).
This _does_ seem wrong to me, but I can't quite pin it down. Comments?

Thanks again!

-- 
==============  xmjschm at harvspha.BITNET ====== There are two kinds of people:
Mike Schmelzer  xmjschm at hscfvax.harvard.edu    They call each other "boring"
============================================== and "weird." -Me



More information about the Comp.lang.c mailing list