
- The C Standard Library
- C Library - Home
- C Library - <assert.h>
- C Library - <ctype.h>
- C Library - <errno.h>
- C Library - <float.h>
- C Library - <limits.h>
- C Library - <locale.h>
- C Library - <math.h>
- C Library - <setjmp.h>
- C Library - <signal.h>
- C Library - <stdarg.h>
- C Library - <stddef.h>
- C Library - <stdio.h>
- C Library - <stdlib.h>
- C Library - <string.h>
- C Library - <time.h>
- C Standard Library Resources
- C Library - Quick Guide
- C Library - Useful Resources
- C Library - Discussion
- C Programming Resources
- C Programming - Tutorial
- C - Useful Resources
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
C library function - ftell()
Description
The C library function long int ftell(FILE *stream) returns the current file position of the given stream.
Declaration
Following is the declaration for ftell() function.
long int ftell(FILE *stream)
Parameters
stream − This is the 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, -1L is returned, and the global variable errno is set to a positive value.
Example
The following example shows the usage of ftell() function.
#include <stdio.h> int main () { FILE *fp; int len; fp = fopen("file.txt", "r"); if( fp == NULL ) { perror ("Error opening file"); return(-1); } fseek(fp, 0, SEEK_END); len = ftell(fp); fclose(fp); printf("Total size of file.txt = %d bytes\n", len); return(0); }
Let us assume we have a text file file.txt, which has the following content −
This is tutorialspoint.com
Now let us compile and run the above program that will produce the following result if file has above mentioned content otherwise it will give different result based on the file content −
Total size of file.txt = 26 bytes
stdio_h.htm
Advertisements