You are on page 1of 1

Program to count the no of Upper case, Lower case alphabets, digits, spaces and special

characters.


#include<fstream.h>
#include<conio.h>

void main()
{
ofstream fout("test");
fout.seekp(0,ios::beg);
fout<<"This_is To coun_No of. charcters "
<<"i.e. a-b,A-B,0-9,special characters saparately";
fout.close();
int sm=0,lr=0,di=0,ex=-1,sp=0;
char tmp;
ifstream fin("test");
clrscr();
cout<<"Text in file: ";
while(!fin.eof())
{
fin.get(tmp);
cout<<tmp;
if(tmp>='0'&&tmp<='9')
di++;
else if(tmp>='a'&&tmp<='z')
sm++;
else if(tmp>='A'&&tmp<='Z')
lr++;
else if(tmp==' ')
sp++;
else if(tmp!='\0')
ex++;

}

cout<<"\nThe no of \nsmall alphabets is :"<<sm
<<"\nlarge alphabets is :"<<lr
<<"\nDigits is :"<<di
<<"\nSpace is :"<<sp
<<"\nSpecial characters is :"<<ex;
getch();
}
OUTPUT

You might also like