Current location - Plastic Surgery and Aesthetics Network - Plastic surgery and beauty - What if scanf assigns a value to a character or string like the integer variable %d in C language?
What if scanf assigns a value to a character or string like the integer variable %d in C language?
int n;

n = scanf("%d ",& ampx);

If (n== 1) printf ("successfully read an integer");

Else printf ("I failed, I didn't look at the numbers");

If you enter a string or something like that, the stored data is of type %d, because this is the format you specified for format reading. You also need to use the return value of the function to judge whether the reading is successful or not. If the reading is successful, the integer is received; if it is not successful, there is nothing in X..

For example, the input string is 123AB, x is pronounced as 123, and the extra AB remains in the input stream.

For example, if the input string is AB 123, the reading statement fails, and X does not read anything.