#include <stdio.h>
#include <ctype.h>
#include <locale.h>
#define BUF_LEN 99
#define STR(string) XSTR(string)
#define XSTR(string) #string
int main (void)
{
int restart = EOF;
char const * old_locale = setlocale(LC_CTYPE, "");
do
{
char str[BUF_LEN + 1];
unsigned int nr_vowel = 0;
unsigned int nr_consonant = 0;
puts("Enter a string: ");
int ret = scanf("%" STR(BUF_LEN) "[^\n]", str);
if(ret == 1)
{
for(size_t i = 0; str[i] != 0; i++)
{
if(isalpha((unsigned char) str[i]))
{
switch(str[i])
{
case 'a': /* fall through */
case 'e':
case 'i':
case 'u':
case 'o':
nr_vowel++;
break;
default:
nr_consonant++;
}
}
}
}
scanf("%*[^\n]"), getchar();
printf("No of vowel: %u\n"
"No of consonant: %u\n"
"\n"
"Again (Y/N)? ", nr_vowel, nr_consonant);
restart = getchar();
if(restart != '\n')
{
scanf("%*[^\n]"), getchar();
}
}
while(toupper(restart) == 'Y');
if(old_locale != NULL)
{
setlocale(LC_CTYPE, old_locale);
}
return 0;
}