
2个回答
展开全部
int main()
{
int iSrcFd = 0;
int iDesFd = 0;
CHAR acReadBuf[128] = {0};
int iReadBytes = 0;
int iWrtBytes = 0;
/* open the source file*/
iSrcFd = open("1.txt",O_RDWR | O_SYNC);
if (iSrcFd < 0)
{
return -1;
}
iReadBytes = read(iSrcFd, acReadBuf, 128);
/* open the des file */
iDesFd = open("2.txt",O_RDWR | O_SYNC);
if (iSrcFd < 0)
{
close(iSrcFd);
return -1;
}
lseek(iDesFd, 0, SEEK_END);
iWrtBytes = write(iDesFd, acReadBuf, 128);
close(iDesFd);
close(iSrcFd);
return 0;
}
lseek(iDesFd, 0, SEEK_END);就是将当前文件读写的位置移动到文件末尾
{
int iSrcFd = 0;
int iDesFd = 0;
CHAR acReadBuf[128] = {0};
int iReadBytes = 0;
int iWrtBytes = 0;
/* open the source file*/
iSrcFd = open("1.txt",O_RDWR | O_SYNC);
if (iSrcFd < 0)
{
return -1;
}
iReadBytes = read(iSrcFd, acReadBuf, 128);
/* open the des file */
iDesFd = open("2.txt",O_RDWR | O_SYNC);
if (iSrcFd < 0)
{
close(iSrcFd);
return -1;
}
lseek(iDesFd, 0, SEEK_END);
iWrtBytes = write(iDesFd, acReadBuf, 128);
close(iDesFd);
close(iSrcFd);
return 0;
}
lseek(iDesFd, 0, SEEK_END);就是将当前文件读写的位置移动到文件末尾
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询
广告 您可能关注的内容 |