Hey, I'm pretty new to programming in general and I would like some help on a program of mine. Basically i'm trying to use a set of data points that are stored in an array to use in a function. When the function returns its value, I get an error of +NAN(i think means not a number?). The function is called dc_offset. None of you can use the code as it requires a .txt file with data points to work but maybe someone can spot an error somewhere? Thanks in advance.
Code:
#include <stdio.h>
#include <math.h>
#include <string.h>
int i;
double sum;
double dc_offset(double []);
int main(void)
{
FILE *inputfp;
double data[2048], time[2048];
int input_status;
char file_name[15];
printf("Enter the file name with the .txt extension: ");
gets(file_name);
inputfp = fopen(file_name, "r");
for (i=0; i<2048; i++) {
for (input_status = fscanf(inputfp, "%lf", &data[i]); input_status!=EOF; input_status = fscanf(inputfp, "%lf", &data[i]));
}
sum = dc_offset(data);
printf("DC offset is: %.8lf\n", sum);
fclose(inputfp);
time[0]=0;
for(i=1; i<2048; i++){
time[i] = time[i-1] + ((double)1/455);
}
return(0);
}
//Functions
double dc_offset(double data[]){
for(i=0; i<2048; i++){
sum += data[i];
}
return(sum);
}