You are on page 1of 1

PROGRAM 3

Program to Count number of alphabets and digits in a


text file
#include<iostream.h>
#include<fstream.h>
#include<conio.h>
#include<ctype.h>
void main()
{
clrscr();
char ch;
int count=0;
int count1=0;
ifstream fil("honey.txt");
while(!fil.eof())
{
fil.get(ch);
if(isalpha(ch))
{
count++;
}
else if(isdigit(ch))
{
count1++;
}
}
cout<<"number of alphabets are : "<<count<<endl;
cout<<"number of digits are : "<<count1<<endl;
fil.close();
getch();
}

Text file contents


1234 by

You might also like