linux文件内容的复制与粘贴
就是文件的打开,读取,与写入。#include#define BUF 1024int main(int argc, char *argv[]){if(argc != 3)perror("file is error\n"),exit(-1);int fw,fr;int count;char *buf = malloc(BUF * sizeof(c
·
就是文件的打开,读取,与写入。
#include <apue.h>
#define BUF 1024
int main(int argc, char *argv[])
{
if(argc != 3)
perror("file is error\n"),exit(-1);
int fw,fr;
int count;
char *buf = malloc(BUF * sizeof(char));
memset(buf, 0, BUF);
if((fr = open(argv[1], O_RDONLY)) < 0)
perror("file is not here"),exit(-1);
if((fw = open(argv[2], O_RDWR |O_CREAT |O_TRUNC, 0700)) < 0)
perror("file creat error"),exit(-1);
while((count = read(fr, buf, BUF)) > 0)
if(write(fw, buf, BUF) < 0 )
perror("write error\n"),exit(-1);
return 0;
}
更多推荐
已为社区贡献1条内容
所有评论(0)