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);

    }

     

  • 相关阅读:
    SSM:Spring整合SpringMVC框架
    SSM:搭建整合环境
    SpringMVC:常用注解
    SpringMVC的入门案例
    base64
    windows设置exe开机自启动
    Python-wmi模块
    Base64String转为图片并保存
    java给图片添加水印图片
    uni-app中封装axios请求
  • 原文地址:https://www.cnblogs.com/mxw09/p/1817285.html
Copyright © 2011-2022 走看看