Please write source code in C Write a program that will open
Please write source code in C++.
Write a program that will open up a text file (open the file in a function), and then read one character at a time until end of file. When done, display how many alphabetic there are, how many digits there is, and how many other character that are not alphabetic nor digits.
Solution
#include<iostream.h>
#include<fstream.h>
#include<string.h>
#include<conio.h>
void countchar(char *filename)
{
ifstream fin(filename);
char ch;
int i,alpha=0,others=0,digi=0;
while(fin.get(ch))
{
i=ch;
if(i>64&&i<91||i>96&&i<123)
alpha++;
else
if(i>47&&i<58)
digi++;
else
others++;
}
cout<<\"No. OF Alphabates:\"<<alpha<<endl;
cout<<\"No. Of Digits:\"<<digi<<endl;
cout<<\"No. Of Others:\"<<others<<endl;
}
int main()
{
char *filename=\"nameofthefile.txt\";
countchar(filename);
return 0;
getch();
}
