• [C]FILE结构体(不知其然,不知所以然)


    minGW 的头文件(stdio.h)中这样定义了 FILE 结构体(注释来自网路):

    file struct
     1 typedef struct   _iobuf  { 
     2          char   *_ptr;             //文件输入的下一个位置 
     3          int       _cnt;             //当前缓冲区的相对位置 
     4          char   *_base;         //指基础位置(应该是文件的其始位置) 
     5          int       _flag;            //文件标志 
     6          int       _file;             //文件的有效性验证 
     7          int       _charbuf;      //检查缓冲区状况,如果无缓冲区则不读取 
     8          int       _bufsiz;        //文件的大小 
     9          char   *_tmpfname; //临时文件名 
    10 } FILE; 

    写了一段程序测试。。

    test code FILE
     1 #include <stdio.h>
     2 #include <stdlib.h>
     3 #include "main.h"
     4 
     5 
     6 int main(int n,char *cmdstr[]){
     7 
     8     FILE *fp = NULL ;
     9 
    10     if(2 != n){
    11         system("pause");
    12         return 0;
    13     }
    14     else{
    15         printf("File name is %s \n",cmdstr[1]);
    16         fp = fopen(cmdstr[1],"rb+");
    17     }
    18 
    19     printf("********** open a file  *********************\n");
    20     printf("_ptr = %s \n", fp->_ptr);
    21     printf("_cnt = %d \n", fp->_cnt);
    22     printf("_base = %s \n", fp->_base);
    23     printf("_flag = %d \n", fp->_flag);
    24     printf("_file = %d \n", fp->_file);
    25     printf("_charbug = %d \n", fp->_charbuf);
    26     printf("_bufsiz  = %d \n", fp->_bufsiz);
    27     printf("_temfname = %s \n", fp->_tmpfname);
    28 
    29     printf("\n");
    30     if(NULL != fp)
    31         fclose(fp);
    32 
    33     printf("********** close the file *********************\n");
    34     printf("_ptr = %s \n", fp->_ptr);
    35     printf("_cnt = %d \n", fp->_cnt);
    36     printf("_base = %s \n", fp->_base);
    37     printf("_flag = %d \n", fp->_flag);
    38     printf("_file = %d \n", fp->_file);
    39     printf("_charbug = %d \n", fp->_charbuf);
    40     printf("_bufsiz  = %d \n", fp->_bufsiz);
    41     printf("_temfname = %s \n", fp->_tmpfname);
    42 
    43     system("pause");
    44     return 1;
    45 }

    效果图:

  • 相关阅读:
    算法----递归
    函数调用栈、任务队列、事件轮询、宏任务、微任务
    苹果浏览器和ios中,时间字符串转换问题
    npm 命令行基本操作
    一些积累(做阿里笔试题)……
    CSS reset
    一些正则表达式的实例,供参考使用
    不同浏览器获取不同高与宽的方法
    盒子模型
    CSS中的字体样式和文本样式
  • 原文地址:https://www.cnblogs.com/alimy/p/2957815.html
Copyright © 2020-2023  润新知