Write a Program to Find the Size of File using File Handling Function.
C Program
#include <stdio.h>int main(){FILE *file;int size = 0;char fileName[100];printf("Enter first file name with full path: ");scanf("%s", fileName);//open file in read modefile = fopen(fileName, "r");if (file == NULL){printf("Error in opening file \n");return -1;}//file pointer at the end of filefseek(file, 0L, SEEK_END);//Take a position of file pointer in size variablesize = ftell(file);printf("The size of given file is : %ld in bytes ", size);//close the filefclose(file);return 0;}
Input:
Enter first file name with full path: C:\Users\merge.txt
Output:
The size of given file is : 44 in bytes
No comments:
Post a Comment