How to compare strings containing numbers just by letters in C

Viewed 166

I need to compare strings comparing letters and numbers just by letters and appearance of a number in C.

For example strings "first%dsecond%dj" should be considered equal to any string like "first[number]second[number]j".

I tried to do that like this:

char *c_i
int i, j;
if (sscanf(c_i, "first%dsecond%dj", &i, &j) == 2 &&
    c_i[strlen(in) - 2] == 'j') {
    printf("%s", c_i);
}

but sscanf ignores everything behind the last number so strings like "first%dsecond%dthird%dj" also give the true value and is printed.

Generally sscanf cares just about the values of letters before the last specifier and I would like to find something that counts also the letters after, like say a comparer that checks the whole strings and gets any number but number.

Of course I can do that by creating my own char* scanner, but I would like to avoid this if there is a simpler way.

2 Answers
Related