home *** CD-ROM | disk | FTP | other *** search
/ Microsoft Programmer's Library 1.3 / Microsoft-Programers-Library-v1.3.iso / sampcode / alde_c / misc / lib / jplc2 / fgets.c < prev    next >
Encoding:
C/C++ Source or Header  |  1988-07-22  |  900 b   |  38 lines

  1. /* 1.0  02-06-85 */
  2. /************************************************************************
  3.  *            Robert C. Tausworthe                *
  4.  *            Jet Propulsion Laboratory            *
  5.  *            Pasadena, CA 91009        1984        *
  6.  ************************************************************************/
  7.  
  8. #include "defs.h"
  9. #include "stdtyp.h"
  10. #include "stdio.h"
  11.  
  12. /************************************************************************/
  13.     STRING
  14. fgets(s, n, fp)        /* Get a string s from FILE fp, at most n chars,
  15.                up to newline or EOF. Newline is part of s.
  16.                Return s if ok, or NULL if empty and EOF.    */
  17. /*----------------------------------------------------------------------*/
  18. STRING s;
  19. FILE *fp;
  20. {
  21.     FAST c;
  22.     STRING t;
  23.  
  24.     t = s;
  25.     while (--n > 0 AND (c = getca(fp)) ISNT EOF)
  26.     {    *s++ = c;
  27.         if (c IS '\n')
  28.             break;
  29.     }
  30.     *s = NULL;
  31.     if (c IS EOF AND s IS t)
  32.         return NULL;
  33.  
  34.     return t;
  35. ;
  36. }
  37.  
  38.