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

  • 相关阅读:
    Netty应用
    原生JDK网络编程- NIO之Reactor模式
    Kafka入门教程
    Java CAS
    Java读写锁
    遍历map的四种方法
    java selector
    Range Sum Query
    Increasing Triplet Subsequence
    Count Numbers with Unique Digits
  • 原文地址:https://www.cnblogs.com/wanghao-boke/p/11260665.html
Copyright © 2011-2022 走看看