Bhuvan InfoTech Android App

Download our Android App and browse Technical News, Projects, Computer Tricks more easily with lots of Interesting Features.

Tuesday, June 14, 2016

Count number of characters in a file | File handling | C program

#include<stdio.h>
#include<conio.h>
void main()
{
 char ch;
 int count=0;
 FILE *fptr;
 clrscr();
 fptr=fopen("text.txt","w");
 if(fptr==NULL)
 {
  printf("File can't be created\a");
  getch();
  exit(0);
 }
 printf("Enter some text and press enter key:\n");
 while((ch=getche())!='\r')
 {
  fputc(ch,fptr);
 }
 fclose(fptr);
 fptr=fopen("text.txt","r");
 printf("\nData of the File is:");
 while((ch=fgetc(fptr))!=EOF)
 {
  count++;
  printf("%c",ch);
 }
 fclose(fptr);
 printf("\nTotal number of characters in file is: %d",count);
 getch();
}
Bhuvan Arora

No comments:

Amazing Deal !