retiring gets(3)

Aled Morris awm at gould.doc.ic.ac.uk
Mon Nov 14 06:32:37 AEST 1988


I was going to suggest the following as a replacement for "gets":

	#define gets(buf) fgets(buf, sizeof(buf), stdin)

since all the examples I've seen of "gets" in use have been:

	char buf[10];
	...
	gets(buf);

But of course it won't work, (a) gets drops the newline at the end, fgets
keeps it, and (b) maybe someone, has written:

	char *buf;
	buf = malloc(10);
	gets(buf);

(although the #define would be fine in this case, it would read only 4
characters :-)

I guess there isn't an easy answer :-(  (but you didn't need me to tell you
that)

Aled Morris
systems programmer

    mail: awm at doc.ic.ac.uk    |    Department of Computing
    uucp: ..!ukc!icdoc!awm    |    Imperial College
    talk: 01-589-5111x5085    |    180 Queens Gate, London  SW7 2BZ



More information about the Comp.lang.c mailing list