home *** CD-ROM | disk | FTP | other *** search
/ DP Tool Club 8 / CDASC08.ISO / NEWS / RADIANCE / SRC / COMMON / FGETLINE.C < prev    next >
C/C++ Source or Header  |  1993-10-07  |  628b  |  35 lines

  1. /* Copyright (c) 1989 Regents of the University of California */
  2.  
  3. #ifndef lint
  4. static char SCCSid[] = "@(#)fgetline.c 2.1 11/12/91 LBL";
  5. #endif
  6.  
  7. /*
  8.  * fgetline.c - read line with escaped newlines.
  9.  *
  10.  *    10/4/89
  11.  */
  12.  
  13. #include  <stdio.h>
  14.  
  15.  
  16. char *
  17. fgetline(s, n, fp)    /* read in line with escapes, elide final newline */
  18. char  *s;
  19. int  n;
  20. register FILE  *fp;
  21. {
  22.     register char  *cp = s;
  23.     register int  c = EOF;
  24.  
  25.     while (--n > 0 && (c = getc(fp)) != EOF) {
  26.         if (c == '\n' && (cp == s || cp[-1] != '\\'))
  27.             break;
  28.         *cp++ = c;
  29.     }
  30.     if (cp == s && c == EOF)
  31.         return(NULL);
  32.     *cp = '\0';
  33.     return(s);
  34. }
  35.