C++ programs
C++ program to implement text processing – counting of vowels, spaces, words and sentences.
Write a C++ program to implement text processing – counting of vowels, spaces, words and sentences.
PROGRAM:
#include <iostream.h>
#include <string.h>
#include<conio.h>
#include<stdio.h>
#define VOWEL_CHARACTERS "AEIOUaeiou"
int main()
{
char str[100];
int i = 0,countv= 0,counts = 0, countw = 0, len = 0 , countl = 0;
clrscr();
// Get the input.
cout<<"www.adkool.com";
cout << "Enter the string : ";
gets(str);
// Get the length of the string.
len = strlen(str);
for(i = 0; i < len; i++)
{
// Check whether it is a vowel character.
if(strchr(VOWEL_CHARACTERS, str[i]) != NULL)
{
// Increment the vowel characters count.
countv++;
}
if(str[i]==' ')
counts++;
if(str[i]!=' ' && str[i+1]==' ')
countw++;
if(str[i]=='\n')
countw++;
}
// Print the result.
cout<<"www.adkool.com";
cout << "\nThe number of vowels characters present above string is\n " << countv;
cout << "\nThe number of spaces present above string is\n" << counts;
cout<< "\nThe number of words present in the sentence is\n"<<countw;
getch();
return 0;
OUTPUT
Enter the string : 5SPACES 3SPACES 2SPACES2
The number of vowels characters present above string is
6
The number of spaces present above string is
12
The number of words present in the sentence is
3