ack/lang/cem/libcc.ansi/stdio/fgets.c

25 lines
350 B
C
Raw Normal View History

1989-05-30 13:34:25 +00:00
/*
* fgets.c - get a string from a file
*/
/* $Header$ */
#include <stdio.h>
char *
fgets(char *s, int n, FILE *stream)
{
register int ch;
register char *ptr;
ptr = s;
while (--n > 0 && (ch = getc(stream)) != EOF) {
*ptr++ = ch;
if ( ch == '\n')
break;
}
1989-06-26 10:37:05 +00:00
if (ch == EOF && ptr == s)
return (char *)NULL;
1989-05-30 13:34:25 +00:00
*ptr = '\0';
1989-06-26 10:37:05 +00:00
return s;
1989-05-30 13:34:25 +00:00
}