sscanf and csv string.

Started by Alessio, September 12, 2007, 04:04:49 PM

Previous topic - Next topic

Alessio

Hi,

I've a string like this:

char *string = "01/01/2004,00:30,-9999,-9999";

How can I use sscanf function to retrieve single values ?
The first and second must be string, the other doubles.
I use following code but it crash. Why ?

int result = sscanf(string, "%[^','],%[^','],%g, %g", string1, string2, d1, d2);

Thanks.


JohnF

You need the addresses of d1 and d2.


int main(void)
{
char string1[90], string2[90];

char *string = "01/01/2004,00:30,-9999,-9999";
float d1, d2;
int result = sscanf(string, "%[^','],%[^','], %g, %g", string1, string2, &d1, &d2);
printf("%s %s %g %g\n", string1, string2, d1, d2);

return 0;
}


John

Alessio