P
P
pshevnin2021-11-23 23:07:31
C++ / C#
pshevnin, 2021-11-23 23:07:31

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

1 answer(s)
W
Wataru, 2021-11-23
@pshevnin

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 question

Ask a Question

731 491 924 answers to any question