Rev | Line | |
---|
[9] | 1 | /*
|
---|
| 2 | * gets.c - read a line from a stream
|
---|
| 3 | */
|
---|
| 4 | /* $Header: /cvsup/minix/src/lib/stdio/gets.c,v 1.1.1.1 2005/04/21 14:56:35 beng Exp $ */
|
---|
| 5 |
|
---|
| 6 | #include <stdio.h>
|
---|
| 7 |
|
---|
| 8 | char *
|
---|
| 9 | gets(char *s)
|
---|
| 10 | {
|
---|
| 11 | register FILE *stream = stdin;
|
---|
| 12 | register int ch;
|
---|
| 13 | register char *ptr;
|
---|
| 14 |
|
---|
| 15 | ptr = s;
|
---|
| 16 | while ((ch = getc(stream)) != EOF && ch != '\n')
|
---|
| 17 | *ptr++ = ch;
|
---|
| 18 |
|
---|
| 19 | if (ch == EOF) {
|
---|
| 20 | if (feof(stream)) {
|
---|
| 21 | if (ptr == s) return NULL;
|
---|
| 22 | } else return NULL;
|
---|
| 23 | }
|
---|
| 24 |
|
---|
| 25 | *ptr = '\0';
|
---|
| 26 | return s;
|
---|
| 27 | }
|
---|
Note:
See
TracBrowser
for help on using the repository browser.