资讯   |   开发   |   选机中心   |   产品大全 | IBM | 惠普 | 联想 | 戴尔 | 苹果 | 神舟
更多: | 华硕 | 明基 | 方正 | 紫光 | TCL | 夏新 | 联宝 | 宏碁 | 七喜 | 长城 | 清华同方 | 海尔 | 三星 | 东芝 | 索尼 | 富士通 | LG | 技术 | ddnoon
当前位置:笔记本 > 软件开发 >
Advertisement
文章正文

请教文件读写简单问题

类型:转载   责任编辑:asp.net   日期:2007/05/23


热门软件下载:


   

打印错误如下:  
  localfd   =   3  
  read   error   =   -1  
  The   buf   is   *  
   
  晕了,感觉挺简单啊  
   
              1   #include   <stdio.h>  
              2   #include   <fcntl.h>  
              3    
              4   int   main()  
              5   {  
              6                   int   localfd;  
              7                   int   len,   len_w;  
              8                   char   buf[10];  
              9                   char   *cp;  
            10    
            11                   len   =   0;  
            12                   localfd   =   open("ccc.test",   O_WRONLY|O_CREAT,   0644);  
            13                   if(localfd   <   0)   printf("open   error\n");  
            14    
            15                   printf("localfd   =   %d\n",   localfd);  
            16    
            17                   len_w   =   write(localfd,   "Hello",   6);  
            18                   if(len_w   <   0)  
            19                                   printf("write   error   %d\n",   len_w);  
            20    
            21                   len   =   read(localfd,   buf,   6);  
            22                   if(len   <   0)  
            23                                   printf("read   error   =   %d\n",   len);  
            24                   printf("The   buf   is   %s\n",   buf);  
            25    
            26                   close(localfd);  
            27                   return   0;  
            28   }

网友回答:

发表者:pacman2000

因为你是WRONLY的,自然不能从这个fd就直接读内容啊!!!


 

 
热门推荐笔记本: IBM笔记本
相关文章:
webmaster:popbb@126.com   最佳浏览:1024X768 MSIE
©2007 popbb.net All Rights Reserved