fgets实现

char *fgets(char *s, int n,  FILE *stream)
{
   register int c;
   register char *cs;
   cs = s;

   while(--n > 0 && (c = getc(stream)) != EOF)
   {
      if((*cs++ =   c) == '\n')
      {
         break;
      }
   }

   *cs = '\0';
   return (c == EOF && cs == s) ? NULL : s ;
}
posted @ 2018-09-17 13:18  thomas_blog  阅读(472)  评论(0编辑  收藏  举报