NO

Author Topic: sscanf and csv string.  (Read 9222 times)

Alessio

  • Guest
sscanf and csv string.
« on: September 12, 2007, 04:04:49 PM »
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

  • Guest
Re: sscanf and csv string.
« Reply #1 on: September 12, 2007, 04:32:32 PM »
You need the addresses of d1 and d2.

Code: [Select]
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

  • Guest
Re: sscanf and csv string.
« Reply #2 on: September 12, 2007, 05:01:53 PM »
what a shame! :-[

thank you!