淡泊明志 宁静致远
分类: C/C++
2006-11-06 09:10:06
#include "stdio.h"
#include "io.h"
#include "fcntl.h "
void Flip()
{
char Buffer[1024],Temp;
int i;
int nReadLength,nRead;
int nLoop,nArrLen;
long nFileLength,SeekOffSet;
int handle;
FILE * SourceFile,*TargetFile;
handle = open("00",O_RDONLY);
nFileLength = filelength(handle);
SourceFile = fopen("00","rb");
TargetFile = fopen("11","wb");
nReadLength = 1;
SeekOffSet = nFileLength - 1024;
nRead = 1024;
nLoop = 512;
nArrLen = 1023;
while(nReadLength != 0)
{
fseek(SourceFile,SeekOffSet,SEEK_SET);
nReadLength = fread(Buffer,sizeof(char),nRead,SourceFile);
for(i=0;i
Temp = Buffer[i];
Buffer[i] = Buffer[nArrLen-i];
Buffer[nArrLen-i] = Temp;
}
fwrite(Buffer,sizeof(char),nReadLength,TargetFile);
if(SeekOffSet < 1024)
{
nRead = SeekOffSet;
SeekOffSet = 0;
nLoop = nRead/2;
nArrLen = nRead -1;
}
else
SeekOffSet -= 1024;
if( nReadLength < 1024 )
nReadLength = 0;
}
fclose(SourceFile);
fclose(TargetFile);
}
main()
{
Flip();
}
本程序在TC2.0下调试通过,源文件文件名是“00”,生成的文件名是“11”。