Thursday 16 November 2017

C Program to Find the Size of File using File Handling Function


Code:

#include   stdio.h

void main(int argc, char **argv)
{
    FILE *fp;
    char ch;
    int size = 0;

    fp = fopen(argv[1], "r");
    if (fp == NULL)
        printf("\nFile unable to open ");
    else 
        printf("\nFile opened ");
    fseek(fp, 0, 2);    /* file pointer at the end of file */
    size = ftell(fp);   /* take a position of file pointer un size variable */
    printf("The size of given file is : %d\n", size);    
    fclose(fp);
}


Output:

$ vi file10.c
$ cc file10.c
$ a.out myvmlinux

File opened The size of given file is : 3791744



More C Programs:












100+ Best Home Decoration Ideas For Christmas Day 2019 To Make Home Beautiful

Best gifts for Christmas Day | Greeting cards for Christmas Day | Gift your children a new gift on Christmas day This Christmas d...