A newbie in C is trying to extract two numbers from a string using sscanf(). The numbers shall be parsed from strings formatted like "7-12", which should result in firstNode = 7
and secondNode = 12
. So I want to get the numbers, the minus sign can be understood as a number seperator. My current implementation is similar to the example I found on this SO answer:
void extractEdge(char *string) {
int firstNode = 123;
int secondNode = 123;
sscanf(string, "%*[^0123456789]%u%*[^0123456789]%u", &firstNode, &secondNode);
printf("Edge parsing results: Arguments are %s, %d, %d", string, firstNode, secondNode);
}
But if I execute the code above, there always is retourned the inital value 123 for both ints. Note that the output of string
gives the correct input String, so I think an invalid string can't be a probable cause for this problem.
Any ideas why the code is not working? Thanks in advance for your help.