Thursday 25 February 2016

This program opens the same program file, reads the characters from it, and increments the counter that indicates the total number of characters, until the end of file (EOF) is encountered.


#include<stdio.h>
#include<unistd.h>
#include<fcntl.h>

int main()
{
 FILE *fp;
 int count=0;
 char ch;

 fp = fopen("charCount.c","r");
 while((ch=fgetc(fp)) != EOF)
 {
count++;
 }

 fclose(fp);
 printf("Total number of characters in the file : %d", count);
 return 0;
}

Output
Total number of characters in the file: 277

No comments:

Post a Comment