昆哥吧 关注:15贴子:242
  • 5回复贴,共1
  • 61.157.97.*
//include 相关头文件
#define BUFFER_SIZE 1024 
int main(int argc,char **argv) 

int from_fd,to_fd; 
int bytes_read,bytes_write; 
char buffer[BUFFER_SIZE]; 
char *ptr; 
if(argc!=3) 

fprintf(stderr,"Usage:%s fromfile tofile\n\a",argv[0]); 
exit(1); 

if((from_fd=open(argv[1],O_RDONLY))==-1) 

//出错处理 

if((to_fd=open(argv[2],O_WRONLY|O_CREAT,S_IRUSR|S_IWUSR))==-1) 

//出错处理 
}
int start=time((time_t *)NULL);
printf("time start:%d\n",start);
while(bytes_read=read(from_fd,buffer,BUFFER_SIZE)) 


if((bytes_read==-1)&&(errno!=EINTR)) break; 
else if(bytes_read>0) 

ptr=buffer; 
while(bytes_write=write(to_fd,ptr,bytes_read)) 


if((bytes_write==-1)&&(errno!=EINTR))break; 
else if(bytes_write==bytes_read) break; 
else if(bytes_write>0) 

ptr+=bytes_write; 
bytes_read-=bytes_write; 


if(bytes_write==-1)break; 

}
//输出处理时间 
//关闭文件 
}


1楼2007-10-15 09:54回复
    • 61.157.97.*
    转换类型:
    sprintf(s,"%d",1234);


    3楼2007-10-15 11:12
    回复
      • 61.157.97.*
      c.c: In function `main':
      c.c:22: parse error before '%' token
      c.c:22: stray '\' in program
      c.c:26: `s' undeclared (first use in this function)
      c.c:26: (Each undeclared identifier is reported only once
      c.c:26: for each function it appears in.)
      c.c:26: stray '\' in program
      c.c:26: `n' undeclared (first use in this function)
      c.c:33: `errno' undeclared (first use in this function)
      c.c:33: `EINTR' undeclared (first use in this function)


      4楼2007-10-22 08:22
      回复
        • 61.157.97.*
        printf(%s\n,"Wrong!") 改成 printf("%s\n","Wrong!")

         添加头文件 #include<errno.h>


        5楼2007-10-22 08:26
        回复
          • 61.157.97.*
          time start:1193012935
          time end:1193012935


          6楼2007-10-22 08:28
          回复
            • 61.157.97.*
            #include<unistd.h>
            #include<sys/types.h>
            #include<sys/stat.h>
            #include<fcntl.h>
            #include<stdlib.h>
            #include<stdio.h>
            #include<errno.h>
             
            #define BUFFER_SIZE 1024
            int main(int argc,char **argv)
            {
            int from_fd,to_fd;
            int bytes_read,bytes_write;
            char buffer[BUFFER_SIZE];
            char *ptr;
            if(argc!=3)
            {
            fprintf(stderr,"Usage:%s fromfile tofile\n\a",argv[0]);
            exit(1);
            }
            if((from_fd=open(argv[1],O_RDONLY))==-1)
            {
             printf("%s\n","Wrong!");
            {
             printf("%s\n","Wrong!");
            }
            if((to_fd=open(argv[2],O_WRONLY|O_CREAT,S_IRUSR|S_IWUSR))==-1)
            {
             printf("s%\n","Wrong!");
            }
            int start=time((time_t *)NULL);
            printf("time start:%d\n",start);
            while(bytes_read=read(from_fd,buffer,BUFFER_SIZE))
            {
             
            if((bytes_read==-1)&&(errno!=EINTR)) break;
            else if(bytes_read>0)
            {
            ptr=buffer;
            while(bytes_write=write(to_fd,ptr,bytes_read))
            {
             
            if((bytes_write==-1)&&(errno!=EINTR))break;
            else if(bytes_write==bytes_read) break;
            else if(bytes_write>0)
            {
            else if(bytes_write>0)
            {
            ptr+=bytes_write;
            bytes_read-=bytes_write;
            }
            }
            if(bytes_write==-1)break;
            }
            }
             int end=time((time_t *)NULL);
             printf("time end:%d\n",end);
             
             close(from_fd);
             close(to_fd);
            return 0;
            }


            7楼2007-10-22 08:29
            回复