Initial revision
This commit is contained in:
Executable
+27
@@ -0,0 +1,27 @@
|
||||
/*
|
||||
* fgets.c - get a string from a file
|
||||
*/
|
||||
/* $Header$ */
|
||||
|
||||
#include <stdio.h>
|
||||
|
||||
char *
|
||||
fgets(char *s, register int n, register FILE *stream)
|
||||
{
|
||||
register int ch;
|
||||
register char *ptr;
|
||||
|
||||
ptr = s;
|
||||
while (--n > 0 && (ch = getc(stream)) != EOF) {
|
||||
*ptr++ = ch;
|
||||
if ( ch == '\n')
|
||||
break;
|
||||
}
|
||||
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