1: /* @(#)fgets.c 2.1 SCCS id keyword */ 2: #include <stdio.h> 3: 4: char * 5: fgets(s, n, iop) 6: char *s; 7: register FILE *iop; 8: { 9: register c; 10: register char *cs; 11: 12: cs = s; 13: while (--n>0 && (c = getc(iop))>=0) { 14: *cs++ = c; 15: if (c=='\n') 16: break; 17: } 18: if (c<0 && cs==s) 19: return(NULL); 20: *cs++ = '\0'; 21: return(s); 22: }