[问题]c source file

C、C++和Java语言
回复
LinuxPing
帖子: 47
注册时间: 2006-03-21 16:21
送出感谢: 0
接收感谢: 0
联系:

[问题]c source file

#1

帖子 LinuxPing » 2006-04-07 12:01

/*My first c programe. */
/*This programe achieve to copy a file to another......*/
#include <stdio.h>

main(int argc,char *argv[]){
int fd1,fd2,read_size;
char buf[512],ch='\n';
if (argc<3){
printf("Please enter TWO filename.\n ");
exit(1);
}

fd1=open(argv[1],0);
if (fd1==-1) {
printf("%s is busy!\n",argv[1] );
exit(1);
}

fd2=creat(argv[2],0666);
if (fd2==-1){
printf("%s can't be created!\n",argv[2]);
exit(1);
}

while(read_size=read(fd1,buf,512)>0)
write(fd2,buf,read_size);

close(fd1);
close(fd2);
}
/* usage:copy src dest*/
/* question:
if source file is text file,then the destination to appear code in confusion
if source file is '.c' ,then the destination just copy a forepart of source file.*/
zbspeed
帖子: 10
注册时间: 2006-10-04 22:20
来自: Chengdu Sichuan
送出感谢: 0
接收感谢: 0
联系:

#2

帖子 zbspeed » 2006-10-08 15:40

while(read_size=read(fd1,buf,512)>0)
赋值运算符的优先级要小于比较运算符,所以WHILE(read_size=(read(fd1,buf,512)>0))一直为TRUE,我感觉是这样
回复

回到 “C/C++/Java”