home *** CD-ROM | disk | FTP | other *** search
- /* gets - get string from standard input or file */
- /* Version 1.1 1982/11/25 21:08 */
- /*
- Kernighan & Ritchie, "The C Programming
- Language", Prentice-Hall, Inc. Englewood Cliffs, NJ
- 1978, p. 155.
-
- submitted by William G. Hutchison, Jr.
- P.O. Box 278
- Exton, PA 19341-0278
- U.S.A.
-
- CompuServe 70665,1307
- */
-
- #ifdef MAINLY
- #else
- #include "a:c80def.h"
- #endif
-
- #ifdef UNIX
- char *
- #endif
- gets(s, n) /* read at most n chars from
- STDIN into string s,
- removing terminal NEWLINE. */
- register char *s;
- register int n;
- {
- register int c;
- register char *cs;
-
- cs= s;
- while (--n > 0 && (c= getchar()) != EOF)
- if ((*cs++ = c) == NEWLINE) {
- cs-- /* remove NEWLINE */;
- break;
- }
- *cs= EOS;
- return ((c == EOF && cs == s)? NULL: s);
- } /* end gets */
-
- #ifdef UNIX
- char *
- #endif
- fgets(s, n, iop) /* read at most n chars from
- file iop into string s */
- register char *s;
- register int n;
- register FILE *iop;
- {
- register int c;
- register char *cs;
-
- cs= s;
- while (--n > 0 && (c= getc(iop)) != EOF)
- if ((*cs++ = c) == NEWLINE) {
- break;
- }
- *cs= EOS;
- return ((c == EOF && cs == s)? NULL: s);
- } /* end fgets */