zoukankan      html  css  js  c++  java
  • ftell函数

    ftell函数用于得到文件位置指针当前位置相对于文件首的偏移字节数,在随机方式存储文件时,由于文件位置频繁的前后移动,程序不容易确定文件的当前位置。

    /***
    a.txt
    ***/
    asd
    gsdert
    dfhjtew
    /***
    ftell.c
    ***/
    #include<stdio.h>
    
    int main()
    {
        FILE *p = fopen("./a.txt","rb");
        fseek(p,2,SEEK_SET);
        char buf[100] = {0};
        fgets(buf,sizeof(buf),p);
        printf("buf = %s",buf);
        printf("ftell = %ld
    ",ftell(p));
        fclose(p);
        return 0;
    }

    运行结果:

    ubuntu1604@ubuntu:~/wangqinghe/C/20190727$ ./ftell

    buf = d

    ftell = 4

    /***
    ftell.c
    ***/
    #include<stdio.h>
    
    int main()
    {
        FILE *p = fopen("./a.txt","rb");
        fseek(p,2,SEEK_SET);
        char buf[100] = {0};
        fgets(buf,sizeof(buf),p);
        printf("buf = %s",buf);
    
        fgets(buf,sizeof(buf),p);
        printf("buf = %s",buf);
    
        printf("ftell = %ld
    ",ftell(p));
        fclose(p);
        return 0;
    }

    运行结果:

    ubuntu1604@ubuntu:~/wangqinghe/C/20190727$ ./ftell

    buf = d

    buf = gsdert

    ftell = 11

  • 相关阅读:
    查看mongodb的状态
    superset----缓存之redis
    superset--presto sql
    linux----之tcpdump小用
    Git版本回退的最佳方式
    SpringBoot 热部署
    不使用Tomcat,手写简单的web服务
    Spring Security 入门
    Maven总结
    git高级用法
  • 原文地址:https://www.cnblogs.com/wanghao-boke/p/11260665.html
Copyright © 2011-2022 走看看