牛骨文教育服务平台(让学习变的简单)
博文笔记

C函数_filelength函数了解

创建时间:2012-12-14 投稿人: 浏览次数:183

_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 && 百科】


声明:该文观点仅代表作者本人,牛骨文系教育信息发布平台,牛骨文仅提供信息存储空间服务。