Scanf question

M

mdh

Scanf ( sect 7.4) contains this description...


On end of file, EOF is returned: note this is different from 0


"which means that the next input character does not match the first
specification in the format string"


Could someone perhaps elaborate on the line in quotes, (not the value
of EOF not being zero).

Thank you.
 
A

Andrew Poelstra

Scanf ( sect 7.4) contains this description...


On end of file, EOF is returned: note this is different from 0


"which means that the next input character does not match the first
specification in the format string"


Could someone perhaps elaborate on the line in quotes, (not the value
of EOF not being zero).

I believe it means that scanf() will return 0 if it cannot
process the first format specifier with the first ("next")
input character.

OTOH, EOF means it ran out of input characters altogether.
 
M

mdh

I believe it means that scanf() will return 0 if it cannot
process the first format specifier with the first ("next")
input character.

OTOH, EOF means it ran out of input characters altogether.


So, this should in essence stop any further processing of this format
specifier and should leave the input untouched?

thank you Andrew
 
M

mdh

mdh wrote: "

BEGIN new.c output

a
That's not an int value.

END new.c output

/* BEGIN new.c */

#include <stdio.h>

int main(void)
{
     int a;

     puts("BEGIN new.c output\n");
     if (scanf("%d", &a) == 0) {
         puts("That's not an int value.");
     }
     puts("\nEND new.c output");
     return 0;

}

/* END new.c */



Thanks Pete.. nice demo.
 
P

Peter Nilsson

mdh said:
So, this should in essence stop any further processing
of this format specifier and should leave the input
untouched?

Whitespace will still be skipped where applicable. However,
in all cases, "The first character, if any, after the input
item remains unread."
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads

scanf internals 11
Scanf Problem 5
question about scanf 11
scanf 2
advanced scanf 2
fflush(stdin), scanf and a space 5
fflush(stdin), scanf and a space 5
scanf behaviour 68

Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,537
Members
45,021
Latest member
AkilahJaim

Latest Threads

Top