从字符串中获取整数

我在从字符串中获取整数并使用它时遇到麻烦。 我有:

char *string = "I 17 24 flying bits"; 

我想把17和24作为整数并使用它们。 指针转换是不可能的,我如何获得这些整数并使用它们?

 int a, b; int count = sscanf(array, "%*s %d %d", &a, &b); if (count == 3) // then you matched three tokens, proceed, else failed to match 

您可以使用strtok标准库函数。 包含标头。

你可以使用strtok以及atoi()和isdigit()。 你可以参考这个链接来了解。 与可以使用的答案之一相同的逻辑。