Return the current position in a stream: how to use ftell : File Pointer « File « C / ANSI-C






Return the current position in a stream: how to use ftell



#include <stdio.h>

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

  file = fopen ("my.txt","rb");
  
  if (file == NULL) 
      perror ("Error reading my.txt.");
  else {
    fseek (file, 0, SEEK_END);
    size = ftell(file);
    
    fclose (file);
    printf ("Size of my.txt is %ld bytes.\n",size);
  }
  return 0;
}


           
       








Related examples in the same category

1.Reset file position indicator to start of the file
2.Set the file pointer to the beginning of a stream: how to use rewind
3.Reposition file pointer to a saved location: how to use fsetpos