Answer the question
In order to leave comments, you need to log in
How to get the value from under the pointer to the beginning of the string?
Good afternoon. I'm using strtok to read data from a C document. As output, I get a pointer to the beginning of the next "word" in the string. How can I equate this "word" to a variable?
Answer the question
In order to leave comments, you need to log in
To convert from a string to a number, you can use atoi() .
However, if the string has a fixed number of numbers known in advance, then it is better to use sscanf() . You can specify the amount you need %d
, separated by commas like this:
sscanf(s, "%d, %d", &a, &b);
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question