Last change
on this file since cbe2c15 was 3ae31e9, checked in by Thomas Lopatic <thomas@…>, 8 years ago |
Imported original source code.
|
-
Property mode
set to
100755
|
File size:
1.2 KB
|
Rev | Line | |
---|
[3ae31e9] | 1 | /*
|
---|
| 2 | =============================================================================
|
---|
| 3 | getword.c -- Get a string from a file
|
---|
| 4 | Version 2 -- 1988-07-13 -- D.N. Lynx Crowe
|
---|
| 5 | =============================================================================
|
---|
| 6 | */
|
---|
| 7 |
|
---|
| 8 | #include "stdio.h"
|
---|
| 9 | #include "ctype.h"
|
---|
| 10 | #include "stddefs.h"
|
---|
| 11 |
|
---|
| 12 | /*
|
---|
| 13 | =============================================================================
|
---|
| 14 | getword(string, ioptr) -- get a string from a file
|
---|
| 15 |
|
---|
| 16 | getword(string, ioptr) is equivalent to fscanf(ioptr, "%s", string)
|
---|
| 17 | but much faster. It returns a NULL pointer on EOF or the end
|
---|
| 18 | of the string when one is found. The return result can be used
|
---|
| 19 | to find the length of the obtained string, or to append further
|
---|
| 20 | characters to the returned string.
|
---|
| 21 | =============================================================================
|
---|
| 22 | */
|
---|
| 23 |
|
---|
| 24 | char *
|
---|
| 25 | getword(string, ioptr)
|
---|
| 26 | register char *string;
|
---|
| 27 | register FILE *ioptr;
|
---|
| 28 | {
|
---|
| 29 | register int c;
|
---|
| 30 |
|
---|
| 31 | while (((c = getc(ioptr)) NE EOF) AND isspace(c))
|
---|
| 32 | ;
|
---|
| 33 |
|
---|
| 34 | if (c EQ EOF)
|
---|
| 35 | return(NULL);
|
---|
| 36 |
|
---|
| 37 | do {
|
---|
| 38 | *string++ = c;
|
---|
| 39 |
|
---|
| 40 | } while (((c = getc(ioptr)) NE EOF) AND (NOT isspace(c)));
|
---|
| 41 |
|
---|
| 42 | *string = '\0'; /* terminate the string */
|
---|
| 43 |
|
---|
| 44 | return(string); /* return a pointer to the end of the string */
|
---|
| 45 | }
|
---|
Note:
See
TracBrowser
for help on using the repository browser.