----- Original Message -----
From: "Daniel K. O." <dan...@ya...>
To: "Dev-Cpp-Users" <dev...@li...>
Sent: Thursday, August 08, 2002 5:04 AM
Subject: Re: [Dev-C++] compiler psychiatrics
> The control string in a scanf() call can be one of these 3 types:
> - format specifier
> - white space
> - non white space
>
> When you use a control string like "%d,%d", scanf will read an int, read
and
> discard a comma, and read another int.
> Same happens with your "%d\n" control string; it will read an int, then
read
> and discard a new-line caracter.
> When scanf() can't find the non white space caracter, it normally finish,
> and some caracters can remain in the keyboard buffer, so it will mess with
> another scanf() calls if you don't use fflush(stdin) before them.
>
>
>
> (this is what I can remember, please someone correct me if I said
something
> incorrect :-) )
> Daniel K. O.
Yes, scanf() is a very dirty function to use (because of the buffer
mechanism)... it should be used only for the most quick-n-dirty programs. In
more 'complete' programs, the safest thing to do would be to read into a
buffer (using cin.getline() or gets()) and then parse it manually.
So the compiler's fine, it's your code. Also, in the for(), while() thing
that Carlos had written about, I'm pretty sure it was a syntax error or
something. It happens very often, and when you read it for verification, you
tend to miss it, because you're expecting something, say a semi-colon, and
you come across a colon, and the eye's in-built error correction routines
fix that :). There's the classic example of counting the number of 'F's in
this sentence:
FINISHED FILES ARE THE RESULT OF YEARS OF SCIENTIFIC STUDY COMBINED WITH THE
EXPERIENCE OF YEARS
Most people count three, but there are actually six (you tend to miss the
'OF's). A computer would count six perfectly. Proof that intelligence isn't
exactly good? <shrug>
The best thing to do when you have an error and you're sure it's in a line,
but you can't find it, is re-type the whole line.
Peace.
___________________________________________________________
Abhijit Shylanath
E-mail: mu...@gm... || ibr...@bi...
Web-site: http://mudeth.tripod.com/
|