文件操作函数之ftell

来源:互联网 发布:淘宝店铺添加客服帐号 编辑:程序博客网 时间:2024/06/01 17:17

函数介绍:

long  ftell(文件指针)用于得到文件指针当前位置,返回相对于文件首的位移量,一般结合 fseek 函数一起使用。

简例:

#include "stdafx.h"#include "stdio.h"#include "process.h"int main(int argc, char* argv[]){//get length of the fileFILE * fp;if ((fp = fopen("test.txt","r")) == NULL){printf("Open fail!\n");exit(0);}fseek(fp,0L,2); // set fp to end of filelong nLen = ftell(fp);printf("The length of the file is %d!\n",nLen);return 0;}


原创粉丝点击