0

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.

1
  • trr with %1d instead of%1f Commented Jul 20, 2019 at 14:02

1 Answer 1

1

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);
Sign up to request clarification or add additional context in comments.

1 Comment

I think you should explain the change.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.