0

I have a buffer in which there are "random" numbers, separated by a coma. For example :

"1589.3,12478.359,485.39971" etc

I need to check the length of the decimal part and the integer part.

I made some research, and I decided to use the strtod() on my buffer, in order to get one number.

However, it doesn't work as intended. So I tried on a simple example :

int number;
char myNumber[10] = "3113.14";
number = strtod (myNumber,NULL);
printf("%d\n", number);

This prints 3113, so I made some research and I found that I should use %f because it's not an integer.

So I corrected it :

int number;
char myNumber[10] = "3113.14";
number = strtod (myNumber,NULL);
printf("%f\n", number);

And then it prints me 0.000000

I tried with a coma (,), with the dot from the regular jeyboard (.) and the dot from the numeric pad (.). They all give me the same result.

I am using dev c++ (I can't choose, I am not admin on my working station).

Thanks for your attention and your help :)

Psycho
  • 1

1 Answers1

4

Use a type double:

double number;
char myNumber[10] = "3113.14";
number = strtod (myNumber,NULL);
printf("%lf\n", number);
this
  • 5,229
  • 1
  • 22
  • 51