ftell

http://www.cplusplus.com/reference/cstdio/ftell/ 点击打开链接
<cstdio>

ftell

long int ftell ( FILE * stream );
Get current position in stream
Returns the current value of the position indicator of the  stream.

For binary streams, this is the number of bytes from the beginning of the file.

For text streams, the numerical value may not be meaningful but can still be used to restore the position to the same position later using  fseek (if there are characters put back using  ungetc still pending of being read, the behavior is undefined).

Parameters

stream
Pointer to a  FILE object that identifies the stream.

Return Value

On success, the current value of the position indicator is returned.
On failure,  -1L is returned, and  errno is set to a system-specific positive value.

Example

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
/* ftell example : getting size of a file */
#include <stdio.h>

int main ()
{
  FILE * pFile;
  long size;

  pFile = fopen ("myfile.txt","rb");
  if (pFile==NULL) perror ("Error opening file");
  else
  {
    fseek (pFile, 0, SEEK_END);   // non-portable
    size=ftell (pFile);
    fclose (pFile);
    printf ("Size of myfile.txt: %ld bytes.\n",size);
  }
  return 0;
}


This program prints out the size of  myfile.txt in bytes (where supported).
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值