3.2

来源:互联网 发布:淘宝试用协议在pc端哪 编辑:程序博客网 时间:2024/04/28 10:16
#include<stdio.h>
#include<stdlib.h>
#include<sys/types.h>
#include<sys/stat.h>
#include<fcntl.h>
#include<errno.h>
#define BUFFER_SIZE 1024


int main()
{
int aim_fd;
int i;
int bytes_write,bytes_read;
// char buffer[BUFFER_SIZE];
char str[]="hello";
char *ptr;/*,*stp=str*/


ptr=str;


if(aim_fd=(open("hello.txt",O_WRONLY|O_CREAT,0644))==-1)
{
        perror("open error!");
exit(-1);
}


for(i=0;i<3;i++)
{
        while(bytes_write=write(aim_fd,ptr,5))
{
if((bytes_write==-1)&&(errno!=EINTR))
break;
else if(bytes_write>0)
{
ptr+=bytes_write;
}


}
}
    
   /* while(bytes_read==read(aim_fd,buffer,BUFFER_SIZE))
{
if((bytes_read==-1)&&(errno!=EINTR))
break;
else if(bytes_read>0)
{
            
}
}
printf("%s",buffer);*/


close(aim_fd);
}
0 0
原创粉丝点击