home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
The C Users' Group Library 1994 August
/
wc-cdrom-cusersgrouplibrary-1994-08.iso
/
listings
/
v_01_06
/
1n06042a
< prev
next >
Wrap
Text File
|
1990-09-30
|
632b
|
36 lines
Listing 9
/*
* fgetid skips leading whitespace and reads an identifier
* from file f into string s. At most n - 1 characters
* are copied to s, and a '\0' is appended. fgetid returns
* the length of s, or EOF if end of file is detected.
*/
int fgetid(FILE *f, char *s, size_t n)
{
char *p = s;
int c;
while (isspace(c = fgetc(f)))
;
if (isalpha(c) || c == '_')
{
do
if (p - s + 1 < n)
*p++ = c;
while (isalnum(c = fgetc(f)) || c == '_');
ungetc(c, f);
*p = '\0';
return p - s;
}
else if (c != EOF)
{
ungetc(c, f);
return 0;
}
else
return EOF;
}