In this post we will write a C++ program to count the characters tab vowels in a line from file.
C++ program to count the characters tab vowels in a line from file.
#include<iostream>
#include<conio.h>
#include<process.h>
#include<fstream>
#include<string.h>
using namespace std;
int main()
{
system("cls");
int p = 0;
int k = 0;
int l = 0;
int spcount = 0;
int tabcount = 0;
char ch;
char arr[150];
char str[] = "IF YOU WANT TO ACCOMPLISH YOUR DREAM THEN WAKE UP";
ofstream a("example.txt");
int m = strlen(str);
for(int j=0;j<m;j++)
{
a.put(str[j]);
}
a.close();
ifstream b("example.txt");
while(b)
{
b.get(ch);
if(ch==' ')
{
p++;
}
if(ch == 'a' || ch == 'e' || ch == 'i' || ch == 'o' || ch == 'u' || ch == 'A' || ch == 'E' || ch == 'I' || ch == 'O' || ch == 'U')
{
k++;
}
if(ch == ' ')
{
spcount++;
}
if(ch == '\t')
{
tabcount++;
}
std::cout<<ch;
}
std::cout<<"\n Number of spaces = "<<spcount;
std::cout<<"\n Number of characters = "<<m;
std::cout<<"\n Number of wovels = "<<k;
std::cout<<"\n Number of tabs = "<<tabcount;
getch();
return 0;
}
Output
IF YOU WANT TO ACCOMPLISH YOUR DREAM THEN WAKE UP Number of spaces = 9 Number of charaacters = 50 Number of vowels = 16 Number of tabs = 1
0 Comments