Function ftell () in C

The function long int ftell (FILE * stream) in standard C Library returns the current file location of the given Stream.

The function long int ftell (FILE * stream) in standard C Library returns the current file location of the given Stream.

Declare ftell () function in C

Below is the declaration for ftell () function in C:

 long int ftell ( FILE * stream ) 

Parameters

stream - This is the pointer to a FILE object that identifies the Stream.

Returns the value

This function returns the current value of position indicator. If an error occurs, -1 is returned, and the global variable errno is set to a positive value.

For example

The following program C illustrates the usage of the ftell () function in C:

 #include int main () { FILE * fp ; int len ; fp = fopen ( "baitapc.txt" , "r" ); if ( fp == NULL ) { perror ( "Xay ra loi khi mo file!!!" ); return (- 1 ); } fseek ( fp , 0 , SEEK_END ); len = ftell ( fp ); fclose ( fp ); printf ( "Tong kich co cua baitapc.txt = %d bytesn" , len ); return ( 0 ); } 

Suppose we have the bait.txt file with the following content:

 Hoc C co ban va nang cao tai QTM !!! 

Compiling and executing the above program will produce the following result if the file has the above content, otherwise it will give different results depending on the content of the file.

Picture 1 of Function ftell () in C

According to Tutorialspoint

Previous post: Function fsetpos () in C

Next lesson: Function fwrite () in C

Update 25 May 2019
Category

System

Mac OS X

Hardware

Game

Tech info

Technology

Science

Life

Application

Electric

Program

Mobile