Ok Thanks for the help. I have now tried another approach. I am able to read the data in with the written function read_data().
Code:
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
char* read_file(char* filename)
{
FILE *fptr;
if ((fptr = fopen(filename,"r")) == NULL){
printf("Error! opening file");
exit(1);
}
fseek(fptr, 0, SEEK_END);
long size = ftell(fptr);
fseek(fptr, 0, SEEK_SET);
char* fcontent = (char*)calloc(size, sizeof(char));
fread(fcontent, 1, size, fptr);
fclose(fptr);
return fcontent;
}
int main(void)
{
char* fp = read_file("data.csv");
printf("%s",fp);
char line[100];
char *sp;
double acceleration;
double rotation;
double temperature;
double totalTemperature;
int count = 0;
while(fgets(line, 100, fp )!= NULL)
{
sp = strtok(line, ",");
acceleration = atof(sp);
sp = strtok(NULL, ",");
rotation = atof(sp);
sp = strtok(NULL, ",");
temperature = atof(sp);
totalTemperature += temperature;
count++;
}
printf("The mean Temperature is: %.14f\n", totalTemperature/count);
return 0;
}
But now the mean temperature can not be calculated. In my first program that was possible. I did not know what is wrong, because after calling the function read_data() I am able to plot the data from the main function. But the following while loop has now problems to evaluate the data. Thanks for a hint.