%[^(]%d,%d)
this tells scanf()
to:
Read all characters which aren't a left (opening) parenthesis;
Then read a decimal integer,
then read a comma,
then read another decimal integer,
then consume the trailing closing parenthesis.
What's missing is that after reading the leading text, you don't actually read the opening paren. So, either change your format string to include that:
%[^(](%d,%d)
Or, even better, consider parsing the string manually. scanf()
format strings are obscure and it's easy to make one slight mistake and then the entire thing goes boom (as just happened to you). How about this instead?
char buf[LINE_MAX];
fgets(buf, sizeof(buf), stdin);
const char *lparen = strchr(buf, '(');
const char *comma = strchr(lparen + 1, ',');
// const char *rparen = strchr(comma + 1, ')'); // is this even needed?
char str[lparen - buf + 1];
memcpy(str, buf, lparen - buf);
str[lparen - buf] = 0;
int n1 = strtol(lparen + 1, NULL, 10);
int n2 = strtol(comma + 1, NULL, 10);
Some demo for goodness sake...