hi

when i try to use atof i get different values every time i run my app

code:

#include <stdio.h>
#include <string.h>
#include <math.h>

int main(int argc, char **argv){
	char* a = "100";
	double b = atof(a);
	printf("%f", b);
}

why do i get different results everytime i run my app???

Recommended Answers

I compiled this with Visual Studio 2010 and ran it 10 times.
I got the same result in debug and release modes.
100.000000

What compiler did you use?

Jump to Post

All 2 Replies

I compiled this with Visual Studio 2010 and ran it 10 times.
I got the same result in debug and release modes.
100.000000

What compiler did you use?

printf("%f", b);

This only outputs a float, not a double. Try %lf

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts learning and sharing knowledge.