zoukankan      html  css  js  c++  java
  • C语言FILE读写操作

    头文件

    #include <stdio.h>
    #include <string.h>


    主函数(字符串读写)
    char write[] = "filewrite";
    FILE *pf;
    //////////////写文件////////////////
    /*pf=fopen("d:\myfile.txt","wb");
    fwrite(&write,sizeof(write),1,pf);*/
    ///////////////写文件////////////////
    
    /////////////////读文件////////////////
    char read[20];
    pf=fopen("d:\myfile.txt","rb");
    fread(&read,sizeof(write),1,pf);	
    printf("%s
    ",read);
    /////////////////读文件////////////////
    fclose(pf);

    主函数(结构体读写)

    stu write;
    strcpy(write.name,"hahha");//在读写不知道字符串大小的情况下要加“”标明字符串结束
    FILE *pf;
    ////////////////写文件////////////////
    //pf=fopen("d:\myfile.txt","wb");
    //fwrite(&write,sizeof(write),1,pf);	
    ///////////////写文件///////////////*/
    
    ///////////////读文件////////////////
    stu read;
    pf=fopen("d:\myfile.txt","rb");
    fread(&read,sizeof(read),1,pf);
    printf("%s
    ",read.name);
    ///////////////读文件////////////////
    fclose(pf);




  • 相关阅读:
    UVA 1660 Cable TV Network
    UVA 1149 Bin Packing
    UVA 1610 Party Games
    UVA 12545 Bits Equalizer
    UVA 11491 Erasing and Winning
    UVA 1611 Crane
    DataTable循环删除行
    SqlBulkCopy使用心得 (大量数据导入)
    JQuery选择器大全
    java学习--GUI3
  • 原文地址:https://www.cnblogs.com/weixinhum/p/3916698.html
Copyright © 2011-2022 走看看