Complete.Org: Mailing Lists: Archives: discussion: March 2000:
[aclug-L] Re: Weekly C quiz
Home

[aclug-L] Re: Weekly C quiz

[Top] [All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index] [Thread Index]
To: discussion@xxxxxxxxx
Subject: [aclug-L] Re: Weekly C quiz
From: Larry Bottorff <mrprenzl@xxxxxxxxxx>
Date: Sun, 12 Mar 2000 01:16:48 -0600
Reply-to: discussion@xxxxxxxxx

Tom Hull wrote:
> 
> John Reinke wrote:
> >
> > Okay, here's the one line answer:
> >
> > while (fscanf(in_file, "%*[\n]%200[^\n]%*[^\n]", buffer) && !feof(in_file))
> 
> This looks like it will fail if the first character in in_file is not \n.
> It also looks like it will fail a last line which does not end in newline,
> since EOF will have been encountered in filling up buffer or discarding
> the overflow.
> 
> The feature of ignoring blank lines seems to be an artifact of the code
> rather than an original requirement. I do think it is appropriate to view
> the consistent stripping of newlines as a requirement.
> 
> I tried writing a test program using the above fscanf(), and it failed as
> I expected. Moreover, I couldn't figure out any way to fix it. (Moving the
> initial "%*[\n]" to the end seemed like the first move, which indeed got
> me the first line, and sometimes a second line.) Which just goes to remind
> me that in >20 years of C programming, I've never written a program which
> actually used fscanf(), for the basic reason that I've never understood
> how it re-synchs on erroneous input. (I've always suspected that it don't.)
> 
> My original suggestion was just to write your own loop. Something like
> this will do:
> 
>     FILE *in_file;
>     char buff[200], *p, *ep = buff + sizeof buff - 1;
>     int c;
> 
>     for ( ; ; ) {
>         p = buff;
>         while ((c = getc(in)) != EOF && c != '\n') {
>             if (p < ep) *p++ = c;
>         }
>         *p = 0;
>         if (c != EOF || p > buff) {
>             /* do something with buff here */
>         }
>         else
>             break;
>     }
> 
It failed for me too, but it's the thought that counts, and I appreciate
the opportunity to explore. I'm taking an algorithms course (CS300) at
WSU. These questions are tangental to something we're doing usually. I'm
learning a lot of C, but I'd like to ask some of the folks out there why
in this day and age I should strive to become a crack C programmer?
After all, everyone knows the best language is Perl, or Java, or C++, or
Modula-X, or, or.... I looked at the Mozilla site and saw a lot of
interesting things being blended (XML, CORBA, a new widget set), but
mainly with C++ (as far as I understood). In addition, a big knock
against Linux on the desktop is the relative primitiveness of the
development tools. MS has pretty IDE's for high-level languages. Your
average Joe programmer can do a VB app fairly quickly, and now Java is
trying to unseat VB in that category. I don't mean to ask "hey, where
are the jobs?", because I know the answer to that: database. But where
is C going? Can you realistically base a career on it, and not have be
highly specialized and move to Silicon Valley to find work? Actually, me
and a few others at WSU want to know.

-- This is the discussion@xxxxxxxxx list.  To unsubscribe,
visit http://tmp2.complete.org/cgi-bin/listargate-aclug.cgi


[Prev in Thread] Current Thread [Next in Thread]