Menu didnt work as intended
I have a program with 3 functions
1. Counting consonants and vowel
2.
3.
I'm using "switch case" and "do while" in this menu, the code is working but when I choose function 1, the menu loop and dont execute the fuction.
I tried with function 2 and 3 but the menu still loop and dont do anything at all.
Here is my code:
Code:
#include <stdio.h>
#include <conio.h>
#include <math.h>
#include <string.h>
#include <stdlib.h>
void func1();
void func2();
void func3();
int main()
{
int choice;
do
{
printf("\t\tMENU");
printf("\n---------------------------------------\n");
printf("\n1. Count consonants and vowels in a string.");
printf("\n2. Login.");
printf("\n3. Sorting string array alphabetically.");
printf("\n4. Exit.");
printf("\n\n-------------------------------------\n");
printf("\nXin moi nhap vao lua chon cua ban: ");
scanf("%d", &choice);
switch(choice)
{
case 1: func1(); break;
case 2: func2(); break;
case 3: func3(); break;
case 4: exit(0); break;
default: printf("\nInvalid. Please choose again.\n");
}
} while(choice != 4);
return 0;
}
void func1()
{
void kiemtrachuoi(char chuoi[100])
{
int consonant = 0, vowel = 0;
for (int i = 0; chuoi[i] != '\0'; i++)
{
if(chuoi[i]== 'a' || chuoi[i]== 'i' || chuoi[i]== 'e' || chuoi[i]== 'u' || chuoi[i]== 'o' ||
chuoi[i]== 'A' || chuoi[i]== 'I' || chuoi[i]== 'E' || chuoi[i]== 'U' || chuoi[i]== 'O')
{
vowel++;
}
else
{
consonant++;
}
}
printf("\nString %s has %d vowels and %d consonants\n",chuoi,vowel,consonant);
return;
}
char chuoi[100];
printf("\nEnter a string: ");
gets(chuoi);
kiemtrachuoi(chuoi);
return;
}
void func2()
{
void checklogin(char user[100], int pass)
{
char userSys[] = "admin";
int passSys = 12345;
if(strcmp(user, userSys) == 0 && pass == passSys)
{
printf("\nLogin successful!!!\n");
}
else
{
printf("\nLogin failed!!!\n");
}
return;
}
char user[100];
int pass;
printf("Enter username: ");
gets(user);
printf("\nEnter password: ");
scanf("%d", &pass);
checklogin(user,pass);
return;
}
void func3()
{
void nhapTen(char ten[5][20])
{
for (int i = 0; i < 5; i++)
{
printf("\nEnter 5 names from keyboard %d: ",i+1);
gets(ten[i]);
}
}
void sapxepTen(char ten[5][20])
{
char temp[20];
for (int i = 0; i < 4; i++)
{
for (int j = i + 1 ; j < 5; j++)
{
if (strcmp(ten[i], ten[j]) > 0)
{
strcpy(temp, ten[i]);
strcpy(ten[i], ten[j]);
strcpy(ten[j], temp);
}
}
}
}
char ten[5][20];
nhapTen(ten);
sapxepTen(ten);
printf("Set of Strings in Ascending alphabetical order: \n");
for (int i = 0; i < 5; i++)
{
printf("\nNumber %d is %s", i+1, ten[i]);
}
return;
}