Here the switch() isn't working properly;not executing the function; & morever the while loop run twice when an invalid choice is given..
#include<stdio.h>
#include<stdlib.h>
#include<ctype.h>
#include<string.h>
#define MAX 100
int vowel_count(char*);
int conso_count(char*);
void to_lower(char*);
void to_upper(char*);
void menu();
int main()
{
int cnt=0;
char data[MAX]=" ";
bool flag=false;
printf("Enter String:\n");
gets_s(data);
menu();
while(flag==false)
{
char ch;
printf("\nEnter ur choice:\t");
scanf("%c",&ch);
switch (toupper(ch))
{
case 'A':
cnt=vowel_count(data);
printf("Vowels: %d",cnt);
break;
case 'B':
cnt=conso_count(data);
printf("Consonants: %d",cnt);
break;
case 'C':
to_upper(data);
break;
case 'D':
to_lower(data);
break;
case 'E':
printf("\n%s\n",data);
break;
case 'F':
printf("\nEnter new String:\n");
gets_s(data);
break;
case 'M':
menu();
break;
case 'X':
flag=true;
break;
default:
printf("Check Again");
break;
}
}
return 0;
}
void menu()
{
printf("\nA) Count the number of vowels in the string\n");
printf("B) Count the number of consonants in the string\n");
printf("C) Convert the string to uppercase\n");
printf("D) Convert the string to lowercase\n");
printf("E) Display the current string\n");
printf("F) Enter another string\n");
printf("\n\nM) Display this menu\n");
printf("X) Exit the program\n");
}