/* *Program to find size of text file */ #include<stdio.h> #define LINE 80 int main(int c, char *argv[]) { /* fp is file pointer, once we open file, it is pointer to opened file */ FILE *fp; char ch; unsigned int size=0; /* Open file for reading * argv[0] is executable program name and argv[1] is first * argument given after executable file */ fp=fopen(argv[1],"r"); /* if we get NULL as return value from fopen() * it means, program is not able to open file or * file may not existed ? or given file path will be wrong */ if(fp == NULL){ printf("Can't open file\n"); return 0; } /* * read characters from file and check size */ while((ch = fgetc(fp)) != EOF){ /* we can add 1 to size every time but better to use sizeof to avoid issues */ size=size+sizeof(ch); ...
C and Linux with Examples!!!