Re: reading a line through scanf



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
.



Relevant Pages

  • Re: How tough a project is this?
    ... ParentId int ... the ParentId would be 0 for a top level category, ... is the Software titles themselves. ... >> What I am hoping for out of this post is some feedback as to how ...
    (microsoft.public.inetserver.asp.general)
  • Re: copy long strings in C
    ... Denis Kasak wrote: ... > Suman wrote: ... >> Coder wrote: ... > No. Use int main. ...
    (comp.lang.c)
  • Revese the output of a file.
    ... Hello everyone just looking for feedback on the following block of code ... on issues or concerns to watch out for, I'm new to C but not ... programming so please be as detailed as possible on do's and do not's ... int line_cnt,n = 0; ...
    (comp.unix.programmer)
  • Re: String appending
    ... Jirka Klaue wrote: ... >> int main ... Prev by Date: ...
    (comp.lang.c)
  • Re: [Fastboot] [PATCH] [REVIEW] Fix irqpoll on IA64 (timer interrupt != 0)
    ... Each and every function example in Documentation/CodingStyle has the ... +void set_timer_interrupt(unsigned int irq) ... I'll repost if I get feedback of the contents of the ... patch. ...
    (Linux-Kernel)