basically its part of a bigger program but its this bit that doesn't work.
its supposed to read the numbers from a txt file (datafile) and write them to an array (fromfile)
the datafile looks like this but it can be up to 40 lines
105683,23,65,0,100
105475,96,72,35,61
105286,23,45,15,86
104762,23,17,5,56
this is what i have so far.
at the moment does the first number correctly, but from then on it just displays zeros till it gets to the end of the array.(see attached image)Code:int main (void) { FILE *datafile, *dataout; int fromfile[200]={0}; int a=0,count = 0, b = 0,e=0 ,s=0, count2 =0; if ((datafile = fopen ("datafile.txt","rt")) == NULL) { printf("\nError opening input file, program exiting\n"); return(1); } if ((dataout = fopen ("dataout.txt","wt")) == NULL) { printf("error opening output file, program exiting\n"); return(1); } printf("\nProgram reading data from file\n"); do {fscanf(datafile, "%d", &fromfile[a]); printf("."); printf("%d",fromfile[a]); //i added this to see what is happening, it won't be in the final program a += 1; count += 1; }while (fromfile[a]!=EOF); stdnts = count/5;
thanks in advance, this is driving me mad.



LinkBack URL
About LinkBacks



I used to be an adventurer like you... then I took an arrow to the knee.