I wrote following code for reading Data and storing it on an array.
Code:
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#define MAX_L 100
int read(double *arr, int size, char *filename);
int read(double *arr, int size, char *filename)
{
int z;
FILE *infile;
infile = fopen(filename,"r");
if (infile==NULL)
{perror("Error");
return 0;
}
for(z=0;;z++)
{
if(fscanf(infile,"%lf",&(arr[z]))==EOF || z>MAX_L)break;
}
return z;
}
//void Print(double *arr, int length);
void Print(double *arr, int length)
{
int i;
for(i = 0;i<length;i++)
{
printf("A[%d]: %d\n",i,arr[i]);
}
}
int main()
{
double f[MAX_L];
int r;
r = read(f, MAX_L, "Points.dat");
Print(f,lesen);
}
It compiles without problems, however it only prints zeros. Can anybody give me a hint what the problem might could be?
Thanks!