void Reverse char filename FILE int buff buff2 bool canExit false fpos

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
void Reverse(char *filename)
{
FILE *f;
int buff, buff2;
bool canExit = false;
fpos_t dbg, len;
if (!(f = fopen(filename, "r+b")))
{
puts("error");
return;
}
len=filelength(fileno(f));
do
{
fread(&buff,sizeof(int),1,f);
//fseek(f,sizeof(int),SEEK_CUR);
fread(&buff2,sizeof(int),1,f);
fseek(f,-sizeof(int),SEEK_CUR);
fwrite(&buff,sizeof(int),1,f);
fgetpos(f,&dbg);
if(dbg==len) canExit=true;
//fseek(f,3*(-sizeof(int)),SEEK_CUR);
fseek(f,2*(-sizeof(int)),SEEK_CUR);
fwrite(&buff2,sizeof(int),1,f);
fflush(f);
} while(!canExit);
fclose(f);
}