kolibrios-gitea/programs/develop/ktcc/trunk/libc/stdio/fgets.c
siemargl af35cc6783 release ktcc 0.9.26
git-svn-id: svn://kolibrios.org@6424 a494cfbc-eb01-0410-851d-a64ba20cac60
2016-05-11 14:53:54 +00:00

26 lines
347 B
C

#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;
}
}