Hi, all. I do search the forum before raise my problem. I need to convert a string to a double, but the atof() or strtod() is not work. Why? What is wrong with my code?
Code:
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
int
main (int argc, char *argv[])
{
char *pr0 = "0.05";
char *ptr;
double pr2, pr3;
pr2 = atof(pr0);
pr3 = strtod(pr0, &ptr);
printf("The number from atof() is: %d\n", pr2);
printf("The number from strtod() is: %d\n", pr3);
return 0;
}
Here is the output after compiled and run:
The number from atof() is: -1717986918
The number from strtod() is: -1717986918
Anyone can help?