//linux 程序设计,copy改
- //a single copy program
- #include<unistd.h>
- #include<sys/stat.h>
- #include<fcntl.h>
- #include<stdlib.h>
- int main()
- {
- char *c;
- int size;//buffer大小
- int in,out;
- int nread;
- int nwrited=0;
- printf("input the size buffer:\n");
- scanf("%d",&size);
- c=(char*)(malloc(sizeof(size*sizeof(char))));
- in=open("re3.mp3",O_RDONLY);
- out=open("re32.mp3",O_WRONLY|O_CREAT,S_IRUSR|S_IXUSR|S_IRGRP|S_IRGRP);
- while(nread=read(in,c,size)>0)
- {
- // printf("nread value: %d\n",nread);
- // sleep(1);
- // printf("writed%d\n",write(out,c,nread));
- write(out,c,nread);
- }
- return 0;
- }
复制代码
gcc 3.2 redhat X环境
为甚么只有输入为1时,才能copy
其他情况输入(如10,100)每次也只copy一个字符? |