Hi everyone, my program doesnt seem to be reading from the textfile raw.txt which i placed in the same directory as the .exe file. Does anyone know why? i have used this function before and it worked in another program. but now when i printf whats in the array a[], all i get is zeros and rubbish values. Pls help me! im desperate!
i got a debug error, run-time check failure #@ - stack aorund the variable 'time' was corrupted.
int main()
{
int channel, maxdatapoints ,size1=0 ,i=0 ,k=0 ,j=0 , totalsize=0 ;
int time;
int ans,f, maxf=0 ,maxf2=0 ,maxans2=0 ,maxans=0 ;
double *a,*temp ,*diff,x;
FILE *fread, *histogramw, *histogramr,*result;
int frequency=0;
printf("Enter the maximum number of data points to compute \n");
scanf("%d", &maxdatapoints);
a=(double *)calloc(maxdatapoints,sizeof(double));
if ((fread = fopen("raw.txt", "r")) == NULL)
{
printf("Cannot open %s\n", "raw.txt");
exit(EXIT_FAILURE);
}
while (!feof(fread) && i<maxdatapoints)
{
fscanf(fread, "%lf %*c %d\n", &time, &channel);
if(channel==1)
{
a[i]=time;
size1=size1+1;
i=i+1;
printf("%lf \n", a[i]);
}
}
fclose(fread);