Yeah. strtok() is better for some things; I don't think this is one of them!
You will run into a problem with sscanf using %s where there are spaces and because it will grab the "," -- so you have to specify characters in the template:
Code:
#include <stdio.h>
struct info {
int num;
int zip;
char state[3];
char city[64];
double longt;
double lat;
int pop;
double AF;
};
int main() {
struct info eg;
char string[]="\"01\",\"35083\",\"AL\",\"HOLLY POND\",86.617441,34.190085,3838,0.00095";
sscanf(string,"\"%d\",\"%d\",\"%[A-Z]\",\"%[a-zA-Z ]\",%lf,%lf,%d,%lf",
&eg.num,&eg.zip,eg.state,eg.city,&eg.longt,&eg.lat,&eg.pop,&eg.AF);
/* check */
printf("%d\n%d\n%s\n%s\n%lf\n%lf\n%d\n%lf\n",
eg.num,eg.zip,eg.state,eg.city,eg.longt,eg.lat,eg.pop,eg.AF);
return 0;
}
Output:
1
35083
AL
HOLLY POND
86.617441
34.190085
3838
0.000950
Notice the 2nd string specifier is [a-zA-Z ], with a "space" inside the brackets.