Categories
Uncategorised

Pointers – Vowels

/* Copyright (C) 2007 Ankur Banerjee. This program is free software: you can redistribute it and / or modify it under the terms of the GNU General Public License as published by the Free Software Foundation version 3 of the License. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. For a copy of the GNU General Public License see http://www.gnu.org/licenses/gpl.html /

/ Pointers – Count vowels /

#include <iostream.h>
#include <conio.h>

void main()
{
clrscr();
char word[200];
int vow = 0;
cout<<endl<<“Enter a string : “;
gets(word);
char *ptr = word;
for (int i = 0; *ptr != ”;
ptr++)
{
switch(
ptr)
{
case ‘A’ :
case ‘a’ :
case ‘E’ :
case ‘e’ :
case ‘I’ :
case ‘i’ :
case ‘O’ :
case ‘o’ :
case ‘U’ :
case ‘u’ : ++vow;
}
}
cout<<“Number of vowels in entered string is : “<<vow;
getch();
}
/* Output */

Enter a string : The quick brown fox jumped over the lazy dog
Number of vowels in entered string is : 12

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.