I'm trying to figure out exactly how scanf
works. If I code something like this:
scanf("%s %d %f", name, &age, &wage);
enter this as standard input:
james 20 34000.25
and then print out name, age, and wage respectively, I get exactly what one would expect, the same thing as I put into standard input. However, if I enter something like this:
scanf("%s/%d/%f", name, &age, &wage);
and I enter this as standard input:
james/20/34000.25
I get the string james/20/34000.25
for the string value and 0 and 0.00000 respectively for the integer and float values. I thought scanf
would treat the slashes the same as it would treat the spaces in the first version. How would I get it so if a user enters a slash separated value, I can appropriately assign the values to variables?