I'm trying to handle user input for 2 following commands:
quit
open <n>
where is an integer.
Right now, my solution is the following:
char input_string[10];
int n;
int trail_index;
//<user input here>
sscanf(input_string, "%s%n %d%n", command, &trail_index, &n, &trail_index);
The trail_index is assigned correctly for me (4 in case of quit command, 6 in case of "open 1"), but since the program may be used with different compilers and platforms, the question is: is the behavior of sscanf guaranteed to work this way when you use the same variable multiple times, or is this undefined behavior that just happens to work for Visual C?