69,381
社区成员
发帖
与我相关
我的任务
分享
#include "stdio.h"//用双引号干什么<stdio.h>
#include "stdlib.h"
#include "fcntl.h"
#include "sys/types.h"
#include "sys/stat.h"
int main(void){
int fp1,fp2;
int size;
char buffer[80];
if((fp1 = open("abc.txt", O_RDONLY)) < 0){
printf("this file is not exit!");
exit(0);//exit(1);0一般表示正确
}
//加O_CREAT需要加mode
if((fp2=open("cd.txt", O_WRONLY |O_CREAT| O_TRUNC, 0666))<0){
printf("overflow!");
exit(0);//同上
}
//不要这个了while(fp1 != -1)
while ((size=read(fp1, buffer, sizeof(buffer)) > 0){
if (write(fp2, buffer, size) != size)) {
perror("write error");
}
}
close(fp1);
close(fp2);
}
不知道对不对!改了下