Domanda

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?

È stato utile?

Soluzione

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();
}
Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top