ugliness in scanf(3)

jack at boring.UUCP jack at boring.UUCP
Tue May 14 02:58:17 AEST 1985

Ahh, the joys of scanf.....

Something I've tried about every year in the last decade but
haven't got to work on any machine is the following :

main() {
    char buf[64];

    printf("Gimme string -");
    scanf("%s\n", buf);
I tried to leave the \n out, putting a space in it's place,
putting a space before the %s, everything.
Never, though, have I succeeded in read the *first* string from
stdin with scanf (the rest is no problem). So, everytime I need
to do this, I fiddle with scanf for an hour or so, and then
replace the scanf by a fgets() or gets().

Question: Am I asking impossible things from scanf, or an I just
soooooo very stupid that I haven't found out how to do this in
many many years????
(I would prefer answers in the form 'it is impossible',
but I'll settle for 'you are stupid', if accompanied by an explanation
*why* I am stupid).

Note that this is about reading the *first* string from stdin.
After that, things are fine, as long as you're careful where
to scan the \n's, etc.
	Jack Jansen, jack at mcvax.UUCP
	The shell is my oyster.

More information about the Comp.lang.c mailing list