saeed amiri
saeed amiri

Reputation: 3

reading double from dynamically unsigned char array

I'm going to read data directly from a "gz" format file. Using "zlib" in c, I read the data from gz file and now I have an unsigned char array namely "str". I want to extract double numbers using "sscanf". here is my code:

printf("%s\n", str);
double d1,d2,d3;
sscanf(str, "%lf %lf %lf", &d1, &d2, &d3);
printf("%lf\n", &d1);
printf("%lf\n", &d2);
printf("%lf\n", &d3);

and the output is:

23.323 1111.232 434434.1
0.000000
0.000000
0.000000

it seems I have successfully read str from gz file, but I cannot read doubles from str.

Upvotes: 0

Views: 70

Answers (1)

RobertBaron
RobertBaron

Reputation: 2854

This will work. This is because %lf expect a double value and you were passing a pointer to a double value.

printf("%lf\n", d1);
printf("%lf\n", d2);
printf("%lf\n", d3);

Upvotes: 1

Related Questions