I wrote this code and it seems there is a problem with the function fseek(). As it affects on the reading from the text file. It makes the function fscanf() reads something like garbage from the file and wrong data. My file contains just float numbers.
FILE *fptr;
if ( !( fptr = fopen( "saving.txt", "r" ))){
printf( "File could not be opened to retrieve your data from it.\n" );
}
else {
fseek(fptr, 0, SEEK_END);
unsigned long len = (unsigned long)ftell(fptr);
if (len > 0) { //check if the file is not empty.
while ( !feof( fptr ) ){
fscanf( fptr,"%f\n", &p.burst_time );
//printf("time = %f\n",p.burst_time);
AddProcess(&l,p.burst_time);
}
}
fclose( fptr );
}
Hint: This part of code to know whether the file is empty or not. If not read from it. I also use the function rewind(fptr); before the loop, but there is no difference.Thanks in advance.