Following the scanset format in this question, I tried a slightly different format to read several numbers instead of one. Here's my data:
722280,"BIRMINGHAM MUNICIPAL AP",AL,-6.0,33.567,-86.750,189
Here's my code:
char buf[400];
char station[11], city[101], state[11];
int tz, lat, lon, alt;
fgets(buf, sizeof buf, file) // yes, I test this
sscanf( buf, "%10[^,],%100[^,],%10[^,],%d,%d,%d,%d", station, city, state, &tz, &lat, &lon, &alt);
When I run this, station, city, state and tz are all set properly. However, lat, lon and alt are not - lat is 1 for instance, lon is 0.
I tried a number of variations on the string, including [^,] after the %d, and removing the commas, without luck.
Yes, I know I can do this with strtok
or one of the many variants, but I'd like to try a sscanf as it matches a similar set of code and I'd like to keep them similar, if possible.
I suspect this is possible and I'm doh'ing on the format?