kolibrios/programs/develop/ktcc/trunk/libc/stdio/fgets.c

26 lines
347 B
C
Raw Normal View History

#include <stdio.h>
char * fgets ( char * str, int num, FILE * stream )
{
int rd = 0;
char c;
while (rd < num - 1)
{
c = fgetc(stream);
if (EOF == c) break;
if ('\n' == c)
{
str[rd++] = c;
break;
}
else
str[rd++] = c;
}
if (0 == rd) return NULL;
else
{
str[rd] = '\0';
return str;
}
}