Re: reading a line through scanf
- From: pete <pfiland@xxxxxxxxxxxxxx>
- Date: Thu, 30 Jun 2005 07:10:31 GMT
Suman wrote:
> Neat, really very neat!
I especially like it for use with text files.
The only possible drawback, is that you get no feedback
on whether or not the lines are longer than LENGTH.
int nonblank_line(FILE *fd, char *line)
{
int rc;
do {
rc = fscanf(fd, "%" xstr(LENGTH) "[^\n]%*[^\n]", line);
if (!feof(fd)) {
getc(fd);
}
} while (rc == 0 || rc == 1 && blank(line));
return rc;
}
int blank(char *line)
{
while (isspace(*line)) {
++line;
}
return *line == '\0';
}
--
pete
.
- References:
- reading a line through scanf
- From: gyan
- Re: reading a line through scanf
- From: pete
- Re: reading a line through scanf
- From: Suman
- reading a line through scanf
- Prev by Date: Re: reading a line through scanf
- Next by Date: Re: reading a line through scanf
- Previous by thread: Re: reading a line through scanf
- Next by thread: Re: reading a line through scanf
- Index(es):
Relevant Pages
|