Hey, i'm trying to sort direct in a file.
The problem is that when i read the first time an int from it,it works! doh.
but when it reads for the second time, it doesn't. ( Neither the swap works.
No signs of errors from the compiler.
FILE *fp=fopen("element.txt","rw+");
fseek(fp, SEEK_SET, 0);
for(i=0;i<n;i++){
fgetpos(fp, &filepos);
fread(&t, sizeof(int), 1, fp);
for(j=i+1;j<n-1;j++){
fgetpos(fp, &filepos2);//t2=NULL;
fread(&t2, sizeof(int), 1, fp); //<< 'broken', t2's value does not change
if(t>t2){
fsetpos(fp, &filepos); //
fwrite(&t2,sizeof(t2),1,fp); // <<All of this doesn't work also.
fsetpos(fp, &filepos2); //File remains the same.
fwrite(&t,sizeof(t),1,fp);} //
}
}
fclose(fp);