Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

about scanf? 1

Status
Not open for further replies.

chopstick

Programmer
Apr 9, 2006
8
SG
I tried to type in a letter "A" when I use the following code,
Code:
scanf("%d",&choice);//I entered 'A'
printf("%d",choice);//I get 32 here!
and choice is integer which is 32 bits, can anyone tell me what happened when the letter is keyed in? if I entered 'A', scanf("%d",&choice); is evaluated as "1" or "0"? thanks.
 
> scanf("%d",&choice);//I entered 'A'
scanf would have returned 0 (no conversion was possible), 'A' would be left on the input stream for something else to deal with, and choice would be left initialised (probably) with whatever was in that variable before scanf was called.



--
 
first, try using scanf("%c", &choice) to read in, also when you print, use scanf("%c", choice), currently you are printing the ASCII value of the letter A which happens to be 32.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top