1989-05-30 13:34:25 +00:00
|
|
|
/*
|
|
|
|
* gets.c - read a line from a stream
|
|
|
|
*/
|
|
|
|
/* $Header$ */
|
|
|
|
|
|
|
|
#include <stdio.h>
|
|
|
|
|
|
|
|
char *
|
|
|
|
gets(char *s)
|
|
|
|
{
|
1989-12-18 15:04:14 +00:00
|
|
|
register FILE *stream = stdin;
|
1989-05-30 13:34:25 +00:00
|
|
|
register int ch;
|
|
|
|
register char *ptr;
|
|
|
|
|
|
|
|
ptr = s;
|
1989-12-18 15:04:14 +00:00
|
|
|
while ((ch = getc(stream)) != EOF && ch != '\n')
|
1989-05-30 13:34:25 +00:00
|
|
|
*ptr++ = ch;
|
|
|
|
|
1989-12-18 15:04:14 +00:00
|
|
|
if (ch == EOF) {
|
|
|
|
if (feof(stream)) {
|
|
|
|
if (ptr == s) return NULL;
|
|
|
|
} else return NULL;
|
|
|
|
}
|
1989-05-30 13:34:25 +00:00
|
|
|
|
|
|
|
*ptr = '\0';
|
|
|
|
return s;
|
|
|
|
}
|