/* 范例:9-24 */
#include <fcntl.h>
#include <io.h>
#include <stdio.h>
#include <stdlib.h>
void main(int argc,char *argv[])
{
int file1,file2;
char buf[512];
if((file1 = open(argv[1],O_RDONLY))==-1)
{
printf("Read file %s Error!\n",argv[1]);
exit(1);
}
if((file2 = open(argv[2], O_WRONLY|O_CREAT))==-1)
{
printf("Create file %s Error!\n",argv[2]);
exit(1);
}
while(read(file1,buf,512)>0)
write(file2,buf,512);
close(file1);
close(file2);
}
程序执行结果:
D:\TC>p9-24 xx.txt out.txt