zoukankan      html  css  js  c++  java
  • 文件操作(读)

    读一行:

    #include<stdio.h>
    #include<string.h>
    #include<stdlib.h>
    const int maxn  = 10;
    int main()
    {
        char s[1024] = {0};
        FILE *p = fopen("/home/exbot/wangqinghe/C/20190716/file.txt","r");
        
        //第一个参数是一个内存地址,第二个参数是这块内存的大小,
    //第三个参数是fopen返回的文件指针
        fgets(s,maxn,p);
        printf(" s = %s
    ",s);
    
        fclose(p);
        return 0;
    }

    读所有:

    #include<stdio.h>
    #include<string.h>
    #include<stdlib.h>
    const int maxn  = 10;
    int main()
    {
        char s[1024] = {0};
        FILE *p = fopen("/home/exbot/wangqinghe/C/20190716/file.txt","r");
        //feof(p) p文件到尾部则返回正
        while(!feof(p))
        {
            memset(s,0,sizeof(s));
            fgets(s,sizeof(s),p);
            printf("%s
    ",s);    
        }
    
        fclose(p);
        return 0;
    }
  • 相关阅读:
    DataFrame转矩阵Np-Array
    十月15
    十月14
    十月14
    十月12
    十月10
    2016-02-22 有无网络 2
    2016-02-22 有无网络的提示 1 h m
    2016-02-20 web view
    20160220 下拉刷新 上拉加载
  • 原文地址:https://www.cnblogs.com/wanghao-boke/p/11196806.html
Copyright © 2011-2022 走看看