home *** CD-ROM | disk | FTP | other *** search
/ The C Users' Group Library 1994 August / wc-cdrom-cusersgrouplibrary-1994-08.iso / vol_100 / 163_01 / fgets.c < prev    next >
Text File  |  1988-01-31  |  512b  |  23 lines

  1. /*
  2. ** get a string from a stream file
  3. ** terminate with \n\0
  4. */
  5. extern int fgetc();
  6.  
  7. fgets(s, n, stream) char *s; int n, *stream; {
  8.   int ch;
  9.   char *str;
  10.   str=s; /* save original value */
  11.   while(--n) {
  12.     ch=fgetc(stream);
  13.     if(ch<0) {
  14.       *s='\0';
  15.       return 0;
  16.       }
  17.     *s++=ch;
  18.     if(ch=='\n') break;
  19.     }
  20.   *s='\0';
  21.   return str;
  22.   }
  23.