john pfeiffer
  • Home
  • Categories
  • Tags
  • Archives

file size ftell

/* John Pfeiffer, 13sep08   file size by fseek/ftell - does it match file size?
YES it does - but counting by cgetc(ifp) windows counts carriage return & linefeed */

#include <stdio.h>

int main(int argc, char* argv[])
{
    long size = 0;
    FILE* ifp;

    if( argc > 2 )
    {   printf("Error! Too many parameters\n");  exit(1);    }

    ifp = fopen(argv[1],"rb");
    if( ifp == NULL )
    {    printf("error opening file\n");}
    else
    {   fseek(ifp, 0, SEEK_END);
        size = ftell(ifp);
        fclose(ifp);
    }

    printf("There were %ld bytes in %s.\n",size, argv[1]);

    return 0;
}

  • « Linux partimage backup restore
  • text to html txt2htm »

Published

Sep 13, 2008

Category

c

~69 words

Tags

  • c 95
  • file 92
  • ftell 1
  • size 4