home *** CD-ROM | disk | FTP | other *** search
/ PC Extra Super CD 1998 January / PCPLUS131.iso / DJGPP / V2 / DJLSR201.ZIP / src / libc / ansi / stdio / fgets.c < prev    next >
Encoding:
C/C++ Source or Header  |  1994-12-26  |  374 b   |  23 lines

  1. /* Copyright (C) 1994 DJ Delorie, see COPYING.DJ for details */
  2. #include <stdio.h>
  3. #include <libc/file.h>
  4.  
  5. char *
  6. fgets(char *s, int n, FILE *f)
  7. {
  8.   int c=0;
  9.   char *cs;
  10.  
  11.   cs = s;
  12.   while (--n>0 && (c = __getc(f)) != EOF)
  13.   {
  14.     *cs++ = c;
  15.     if (c == '\n')
  16.       break;
  17.   }
  18.   if (c == EOF && cs == s)
  19.     return NULL;
  20.   *cs++ = '\0';
  21.   return s;
  22. }
  23.