Initial revision
This commit is contained in:
27
lib/stdio/gets.c
Executable file
27
lib/stdio/gets.c
Executable file
@@ -0,0 +1,27 @@
|
||||
/*
|
||||
* gets.c - read a line from a stream
|
||||
*/
|
||||
/* $Header$ */
|
||||
|
||||
#include <stdio.h>
|
||||
|
||||
char *
|
||||
gets(char *s)
|
||||
{
|
||||
register FILE *stream = stdin;
|
||||
register int ch;
|
||||
register char *ptr;
|
||||
|
||||
ptr = s;
|
||||
while ((ch = getc(stream)) != EOF && ch != '\n')
|
||||
*ptr++ = ch;
|
||||
|
||||
if (ch == EOF) {
|
||||
if (feof(stream)) {
|
||||
if (ptr == s) return NULL;
|
||||
} else return NULL;
|
||||
}
|
||||
|
||||
*ptr = '\0';
|
||||
return s;
|
||||
}
|
||||
Reference in New Issue
Block a user