69,371
社区成员
发帖
与我相关
我的任务
分享
#include <stdio.h>
#include <unistd.h>
#include <fcntl.h>
#include <sys/types.h>
#include <sys/stat.h>
int main(void)
{
const char *pathName = "f.c";
int in, out, flag;
char buffer[1024];
in = open("z.c", O_RDONLY, S_IRUSR);
if (-1 == in) // 打开文件失败,则异常返回
{
printf("open file z.c error !\n");
return -1;
}
out = creat(pathName, S_IWUSR);
if (-1 == in) // 创建文件失败,则异常返回
{
printf("create file %s error !\n", pathName);
return -1;
}
while ((flag = read(in, buffer, 1024)) > 0)
{
write(out, buffer, flag);
}
close(in);
close(out);
printf("copy file z.t to %s finish !\n", pathName);
return 0;
}
write(out,buffer,flag)
int main(int argc, char * argv[])
{
// ...
return 0;
}