What should [fs]scanf return?

Dale Schumacher dal at midgard.Midgard.MN.ORG
Fri Jan 20 03:26:18 AEST 1989


The following question appeared in comp.os.minix recently.  I thought
it would get a better/faster answer in comp.lang.c, thus this crossposting.

In article <588 at forty2.UUCP> poole at forty2.UUCP (Simon Poole) writes:
|Somehow I've got the feeling that this has been hashed thru before, but
|I probably wasn't paying attention then. Consider the following code
|fragment:
|
|........
|    printf("%d\n",sscanf("123","%d",&dummy));
|    printf("%d\n",sscanf("123","%*d",&dummy));   
|    printf("%d\n",sscanf("123:456","%d:%d",&dummy,&dummy));
|    printf("%d\n",sscanf("123:456","%*d:%*d"));
|........
|
|What should it print?
|
|Minix-ST 1.1     BSD 4.2    I think it should be   
|
|    1             1                1
|    1             -1               0
|    3             2                2
|    3             -1               0
|
|
|K&R first edition says (about scanf):
|
|'It returns as its value the number of sucessfully matched and assigned
| input items'



More information about the Comp.lang.c mailing list