Hi There
I wondered if you could possibly help me
I have a data file that I want to read into an array and then put into bins of equal size so I can plot a histogram in excel. I have written the following code which seems to compile fine but does not actually work, the programme never completes! If someone could tell me where I am going wrong it would be greatly appreciated
Code:#include <stdio.h> int main() { int i, time[78],j; float hit[1800],value,event; FILE *fp, *fw; fp = fopen("damadata.xlsx" , "r"); fw = fopen("bindata.txt", "w"); for (i=0; i<1800; i++) /* enter loop to set array elements to zero*/ { hit[i] = 0; time[i] = 0; } /*All array elements now set to zero, exit loop*/ for(i=0; i<1800; i++) /*Enter loop to read all lines of data into hit array*/ { fscanf(fp,"%f\n", &event); /*Each line is read into a seperate array element*/ hit[i]=event; } for (i = 0; i < 1800; i++) /*Now cycle through array containing data elements*/ { /*Open Loop 1*/ value = hit[i]; /*Value now equal to element i of array*/ for (j = 0; j < 77; j++) /*enter loop to bin data into 77 bins of group of 60*/ { /*Open Loop 2*/ if (value >= j*60 && value < ((j+1)*60)) /*Tests if the value lies within a particular boundary*/ { time[j] = time[j] + 1; /*If it is add 1 element into bin j*/ } else { time[j] = time[j]; /*If not element j remains the same*/ } } /*Close Loop 1*/ } /*Close Loop 2*/ for (j = 0; j <77; j++) /*Loop to print the number of data points in each bin*/ { fprintf(fw, "%d\t%f\n" , j , &time[j]); /*Prints the bin number and the number of elements in this bin*/ } return(0); }



2Likes
LinkBack URL
About LinkBacks



