Hi all!

I´m having a problem, I'm reading from a txt file values (doubles) but my cout outputs the following:

-9.25596e+061
-9.25596e+061
-9.25596e+061
-9.25596e+061
Press any key to continue

When it should read this:
1.986772
2.607455
0.000000
0.000000

The code is:

#include "stdafx.h"
#include <stdlib.h>
#include <stdio.h>
#include <time.h>
#include <iostream.h>
#include <math.h>

int main(int argc, char* argv[])
{

	FILE *fINPUT;

	int const dim = 4;
	double in[dim];
	
	if( (fINPUT  = fopen( "log_input.txt", "r" )) == NULL )
	{
		printf( "The file 'log_input.txt' was not opened\n" );
		exit(1);
	}
	
	for(int i=0; i<dim; i++)
	{
		fscanf( fINPUT, "%f", &in[i]);
		cout << in[i] << "\n";
	}
	
	return 0;
}

Can you tell me what am I doing wrong?

thanks

The scanf format modifier for a double is %lf, not %f.

The scanf format modifier for a double is %lf, not %f.

That's it :o

Thanks ;)

Be a part of the DaniWeb community

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