Reputation: 186
I'm trying to use the return value of sscanf function. The problem is that in the file that I'm reading, some lines may contain different number of integers. How can I tackle this problem?
Upvotes: 1
Views: 311
Reputation: 13134
int values[5];
int values_per_line = sscanf_s(line_buffer, "%d %d %d %d %d", &values[0], &values[1], &values[2], &values[3], &values[4]);
`
Return Value
Each of these functions [including s_sscanf()] returns the number of fields that are successfully converted and assigned; the return value does not include fields that were read but not assigned. A return value of 0 indicates that no fields were assigned. The return value is EOF for an error or if the end of the string is reached before the first conversion.
Upvotes: 1