How would I verify that there is only one white space between each parameter, string, int, int in this string "string int int" using sscanf?
Asked
Active
Viewed 112 times
1
-
Well right now I'm just iterating through the string and checking to make sure there is only one space between each argument. There must be a better nicer way of doing it using sscanf, but I'm having trouble coming up with a format string to that allow me to check that. – HighLife Dec 07 '13 at 23:47
-
1Please post your code then! – user703016 Dec 07 '13 at 23:48
1 Answers
0
Use %n
// "string int int"
char dest[100];
int d[2];
int n[4];
int result = sscanf(buf, "%99s%n %n%d%n %n%d",
dest, &n[0], &n[1], &d[0], &n[2], &n[3], &d[1]);
if ((result == 3) && (n[1] - n[0] == 1) && (n[3] - n[2] == 1)) {
LifeIsGood();
}

chux - Reinstate Monica
- 143,097
- 13
- 135
- 256