|
发表于 2003-12-5 22:22:22
|
显示全部楼层
回复: 求助
- int main()
- {
- int fd,i=0,j=0;
- char buf[5];
- if((fd=open("receive",O_RDWR|O_CREAT,0644))==-1){
- printf("open file error!\n");
- return;
- }
- if((i=write(fd,"abc\r",[color=red]5[/color] ))==0){//当把5变成更大的数,如10或。。。执行less receive,有趣的事会发生!!
- printf("write error!\n");
- exit(1);
- }
- [color=red] //close(fd);
- //fd=open("receive",O_RDONLY);[/color]
- if((j=read(fd,buf,5))==0){
- printf("read error!\n");
- exit(1);
- }
- printf("i=%d,j=%d,%s\n",i,j,buf);
- close(fd);
- }
复制代码
试试这段代码
再试试去掉注释后的代码 |
|