C Library Function - ftell()
Description
C library function *long int ftell(FILE stream) Return the current file position of the given stream stream.
Declaration
Below is the declaration of the ftell() function.
long int ftell(FILE *stream)
Parameters
- stream -- This is a pointer to a FILE object that identifies the stream.
Return Value
This function returns the current value of the position indicator. If an error occurs, it returns -1L and the global variable errno is set to a positive value.
Example
The following example demonstrates the use of the ftell() function.
#include
int main ()
{
FILE *fp;
int len;
fp = fopen("file.txt", "r");
if( fp == NULL )
{
perror ("打开文件错误");
return(-1);
}
fseek(fp, 0, SEEK_END);
len = ftell(fp);
fclose(fp);
printf("file.txt 的总大小 = %d 字节\n", len);
return(0);
}
Suppose we have a text file file.txt, with the following content:
This is runoob.com
Let's compile and run the above program; if the file contents are as shown above, this will produce the following result; otherwise, it will give a different result depending on the file contents:
file.txt 的总大小 = 19 字节
C Standard Library -