Count Number of Characters in File

Опубликовано: 18 Май 2026
на канале: Solution Manual
93
0

// C Program to count total number of char in file

// FUNCTIONS USED

//fseek()
//ftell()
//printf()

int main()
{
// CREATE A FILE POINTER
FILE *fp;

//CREATE A FILE WITH WRITE MODE

fp=fopen("Char_count.txt","w");

//WRITE SOMETHING IN YOUR FILE

fputs("This is test file to count number of char !!!!",fp);

// PLACE THE CURSOR IN LAST POSITION USING FSEEK() FUNCTION

fseek(fp,0,SEEK_END); // CURSOR IS SET TO LAST POSITION WITH ZERO DISTANCE

//PRINT THE CURSOR POSITION USING FTELL() FUNCTION

printf("%ld",ftell(fp));

//CLOSE THE FILE POINTER

fclose(fp);

return 0;
}