zoukankan      html  css  js  c++  java
  • C语言操作文件

    http://blog.chinaunix.net/u1/37000/showart_338364.html

    // C语言读写文件.cpp : 定义控制台应用程序的入口点。
    //

    #include "stdio.h"
    #include "string.h"

    void write()
    {
        FILE *fp;
        //只写打开或建立一个文本文件,只允许写数据
        fp=fopen("D:\\c.txt","wt");
        if(fp!=NULL)
        {
            char *str="C语言创建txt";
            //fputs(str,fp);
            fwrite(str,strlen(str),1,fp);
            
        }
        //fflush(fp);
        fclose(fp);
    }

    void read()
    {
        FILE *fp;
        //只读打开一个文本文件,只允许读数据
        fp=fopen("D:\\c.txt","rt");
        if(fp!=NULL)
        {
            printf("文件大小为:%d\n",99);
        }else
        {
            printf("出错\n");
        }
        fclose(fp);
    }
    void main()
    {
        //read();
        long size;
        FILE *fp;
        
        fp=fopen("D:\\c.txt","rb");
        fseek(fp,0,SEEK_END);
        size=ftell(fp);

        fclose(fp);
        printf("%d\n",size);

    }

     

  • 相关阅读:
    vim中ctags应用
    LCD屏参数及应用举例
    modbus概述
    Modbus常用
    git常用操作
    linux内核学习
    截图工具gsnap
    信号signal编号及意义及一般处理
    oracle 表空间 数据文件 表的关系
    IBM MQ 2035 或 2013认证错误的解决方法
  • 原文地址:https://www.cnblogs.com/mxw09/p/1817285.html
Copyright © 2011-2022 走看看