CSDN首页 空间 新闻 论坛 Blog 下载 读书 网摘 搜索 .NET Java 视频 接项目 求职 在线学习 买书 程序员 通知
(图)邪恶的韩国UMPC 使用 Java 编写数据库应用新规范
CSDN社区
搜索 收藏 打印 关闭
CSDN社区 >  C/C++ >  C语言

文件的读写

楼主FBIq(aiby)2006-12-01 08:13:35 在 C/C++ / C语言 提问

怎么判断文件的当前状态?是reading,   writeing。 问题点数:50、回复次数:3Top

1 楼chary8088(天使鱼儿)回复于 2006-12-01 08:30:50 得分 0

函数名:   stat    
  功     能:   读取打开文件信息    
  用     法:   int   stat(char   *pathname,   struct   stat   *buff);    
  程序例:    
   
  #include   <sys\stat.h>    
  #include   <stdio.h>    
  #include   <time.h>    
   
  #define   FILENAME   "TEST.$$$"    
   
  int   main(void)    
  {    
        struct   stat   statbuf;    
        FILE   *stream;    
   
        /*   open   a   file   for   update   */    
        if   ((stream   =   fopen(FILENAME,   "w+"))   ==   NULL)    
        {    
              fprintf(stderr,   "Cannot   open   output   file.\n");    
              return(1);    
        }    
   
        /*   get   information   about   the   file   */    
        stat(FILENAME,   &statbuf);    
   
        fclose(stream);    
   
        /*   display   the   information   returned   */    
        if   (statbuf.st_mode   &   S_IFCHR)    
              printf("Handle   refers   to   a   device.\n");    
        if   (statbuf.st_mode   &   S_IFREG)    
              printf("Handle   refers   to   an   ordinary   file.\n");    
        if   (statbuf.st_mode   &   S_IREAD)    
              printf("User   has   read   permission   on   file.\n");    
        if   (statbuf.st_mode   &   S_IWRITE)    
              printf("User   has   write   permission   on   file.\n");    
   
        printf("Drive   letter   of   file:   %c\n",   'A'+statbuf.st_dev);    
        printf("Size   of   file   in   bytes:   %ld\n",   statbuf.st_size);    
        printf("Time   file   last   opened:   %s\n",   ctime(&statbuf.st_ctime));    
        return   0;    
  }    
       
  Top

2 楼goodluckyxl(被人遗忘的狗)回复于 2006-12-01 08:49:58 得分 0

_stat   中文件属性的位图模式下可以看到具体的读写属性Top

3 楼FBIq(aiby)回复于 2006-12-04 12:33:00 得分 0

#include   <stdio.h>  
  int   main(void)  
  {  
  FILE   *fp   =   fopen   ("d:\\abc.txt",   "r+");  
   
  if   (NULL   ==   fp)  
  return   0;  
  getc(fp);    
  fputc('t',   fp);  
   
  fclose(fp);  
  return   0;  
  }  
  文件的内容没有改变,为什么会这样?  
  注:该文件已成功读取Top

相关问题

关键词

得分解答快速导航

  • 帖主:FBIq

相关链接

  • C/C++ Blog
  • C/C++类图书
  • C/C++类源码下载

广告也精彩

反馈

请通过下述方式给我们反馈
反馈
提问
惹火投票。。火热进行中...
网站简介|广告服务|VIP资费标准|银行汇款帐号|网站地图|帮助|联系方式|诚聘英才|English|问题报告
北京创新乐知广告有限公司 版权所有, 京 ICP 证 070598 号
世纪乐知(北京)网络技术有限公司 提供技术支持
Copyright © 2000-2008, CSDN.NET, All Rights Reserved
GongshangLogo