dpalyca755
asked on
SSCANF
What does this piece of code do?
It is a condition in a For Loop.
What does ==1 mean and inversely what would a 0 mean?
"sscanf(route_parameter+ne t_offset, "%s %n", &wpt_name[x][0], &offset) == 1"
It is a condition in a For Loop.
What does ==1 mean and inversely what would a 0 mean?
"sscanf(route_parameter+ne
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
> sscanf(route_parameter+net _offset, "%s %n", &wpt_name[x][0], &offset) == 1
%s will read the string (that is stored at route_parameter+net_offset ) upto first space.
And this will be stored in wpt_name[x][0].
%n will keep the count of number of characters eaten by %s and that will get stored in offset.
So, if the string stroed in route_parameter is "string 1234",
%s will read 's', 't', 'r', 'i', 'n', 'g' and after this there is a space. So, including space, the number of characters read is 7. So, the offset will get the value 7.
> What does ==1 mean and inversely what would a 0 mean?
And sscanf() returns the number of input items successfully matched.
Now, in the sscanf() that you have, there is only one %s and that is the only one to be matched,
If the string at route_parameter+net_offset is a null string, then %s will not read anything and sscanf will return 0. If there is a string, then it will return 1.
%s will read the string (that is stored at route_parameter+net_offset
And this will be stored in wpt_name[x][0].
%n will keep the count of number of characters eaten by %s and that will get stored in offset.
So, if the string stroed in route_parameter is "string 1234",
%s will read 's', 't', 'r', 'i', 'n', 'g' and after this there is a space. So, including space, the number of characters read is 7. So, the offset will get the value 7.
> What does ==1 mean and inversely what would a 0 mean?
And sscanf() returns the number of input items successfully matched.
Now, in the sscanf() that you have, there is only one %s and that is the only one to be matched,
If the string at route_parameter+net_offset
This question has been classified as abandoned and is closed as part of the Cleanup Program. See the recommendation for more details.
net_offset is obviously a numeric value that gets updated within the loop to point to the next combination.
After each successful loop (ie. the result of sscanf == 1) the wpt_name array entry at position x in the array contains the string value.
The offset variable will contain the number value from the combination. What it is will be relative to the application.