Understanding Scanf - dealing with formatted input

c

Solution

`%s` matches non-whitespace characters (and it's a greedy match: it's not going to backtrack to see if some other match is possible) To match non-forward slash characters, use `%[^/]`

(also, note that the space character (match zero or more whitespace characters) in the scanf string has a very different behavior from a non-space non-percent character, such as `'/'` (match exactly `'/'`)

Problem

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?

Original source