我想检查我的文本文件是否包含数据。如果文件包含数据,我想读取它。我的问题是我不知道在if语句中应该写什么条件。 提示:我尝试使用fseek和ftell函数,但没有任何效果。 我想知道为什么在if语句中的这个条件不能正常工作?
FILE *fptr;
if(ftell(fptr)!=0){ //check if the file is not empty.
if ( !( fptr = fopen( "saving.txt", "r" ))){
printf( "File could not be opened to retrieve your data from it.\n" );
}
else{
while ( !feof( fptr ) ){
fscanf( fptr, "%f\n", &p.burst_time );
AddProcess(&l,p.burst_time);
}
fclose( fptr );
}
}