C函数_filelength函数了解
_filelength()---->Gets the length of a file.
原型:
long _filelength(int fd );__int64 _filelengthi64(int fd );
fd:Target the file descriptor.
取文件长度字节数.
Both
_filelength and _filelengthi64return the file length, in bytes, of the target file associated withfd
DEMO1:
#include <stdio.h> #include <string.h> #include <fcntl.h> #include <io.h> int main(void) { FILE *fp; long file_handle; char buffer[]="0123456789"; /*create a file containing 10 bytes*/ if((fp=fopen("hgj.txt","wb+"))==NULL) { fprintf(stderr,"ERROR! "); getchar();getchar(); return -1; } fwrite(buffer,strlen(buffer),1,fp); fseek(fp,0,SEEK_SET); //疑惑,这里不加fseek,最后结果是0 /*display the size of file*/ printf("file length in bytes:%ld ",_filelength(_fileno(fp))); fclose(fp); system("pause"); return 0; }
【FROM MSDN && 百科】
声明:该文观点仅代表作者本人,牛骨文系教育信息发布平台,牛骨文仅提供信息存储空间服务。
- 上一篇: C++获取文件字节数
- 下一篇: js数组的截取与排序