linux 下文件的批量复制


头文件是Unix高级编程的头文件


哥哥大神看到后,若有能有优化或有错误的地方,向小白提出



#include


#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);


int i = 2,temp;
for(temp = i; temp < argc; temp++)
{

if((fr = open(argv[1], O_RDONLY)) < 0)
perror("file is not here"),exit(-1);

if((fw = open(argv[temp], O_RDWR |O_CREAT |O_TRUNC, 0600)) < 0)
perror("file creat error"),exit(-1);
while((count = read(fr, buf, 10)) > 0 )
if(write(fw, buf, 10) < 0 )
perror("write error\n"),exit(-1);
close(fr);
close(fw);


}
return 0;
}

你可能感兴趣的:(linux,and,centos)