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

    文件的打开操作fopen 打开一个文件

    FILE *fopen(const char*_restrict,const char*_restrict);

    FILE *是返回文件的内存地址(错误就为NULL)

    第一个const char*_restrict是文件在磁盘里面的路径

    第二个const char*_rentrict是文件的读取方式 r,w,a

    当mode为w的时候,如果文件不存在,就会自动为我们创建一个文件。

    当mode为r的时候,如果文件不存在,就会错误。

    读取文件的内容fgetc(fp)每次读取一个字符,当值为EOF的时候就表示到达文件的末尾了

    fgets(temp,100,fp);读取多个字符串

    写入数据

    fputc('x',fp),一次只能写入一个字符

    fputs(string,fp),一次写入一个字符串

    typedef struct{

      char name[10];

      int age;

    }Student;

    写入一定结构的数据

    fwrite(&xw, sizeof(Student), 1, fp);

    读取一个数据

    fread(&xw, sizeof(Student), 1, fp);

    使用fclose(fp)关闭打开的文件

  • 相关阅读:
    HTML页引用CSS
    C#反射
    Marshal.SecureStringToBSTR
    SQL语句创建表和数据库
    抽象类和抽象方法
    3 Sum Closest
    Chapter 2: Binary Search & Sorted Array
    Spiral Matrix
    Pascal's Triangle
    Plus One
  • 原文地址:https://www.cnblogs.com/zhaopengs/p/5052256.html
Copyright © 2011-2022 走看看