i want to make a menu using C but after i typed all the functions included in the menu, i don't know how to put them together (i am a beginner)and form a complete program like this:
1. count no. of words
2. count no. of vowels
3. Count no. of capital letters
4. Reverse text
5. Capitalize the first character
Please enter your choice: _
here are codes that i hv typed so far:
Code:
/*count words*/
#include <stdio.h>
#include <string.h>
int main()
{
char text[800];
int count=0, i;
printf("Please input text: ", stdout);
fgets(text, 800, stdin);
if (text[0] != ' ')
count++;
for (i=1; i<strlen(text); i++)
if ((text[i-1] == ' ') && (text[i] != ' '))
count++;
printf("\nThe total number of words is %d.\n\n", count);
return 0;
}
Code:
/*count vowels*/
#include <stdio.h>
#include <string.h>
int main()
{
char sentence[800];
int a=0, e=0, i=0, o=0, u=0;
int j;
printf("Please input text: ", stdout);
fgets(sentence, 800, stdin);
for (j=0; j<strlen(sentence); j++)
{
if ((sentence[j] == 'a') || (sentence[j] == 'A'))
a++;
else if ((sentence[j] == 'e') || (sentence[j] == 'E'))
e++;
else if ((sentence[j] == 'i') || (sentence[j] == 'I'))
i++;
else if ((sentence[j] == 'o') || (sentence[j] == 'O'))
o++;
else if ((sentence[j] == 'u') || (sentence[j] == 'U'))
u++;
}
printf("\nThe total number of 'a' is %d\n", a);
printf("The total number of 'e' is %d\n", e);
printf("The total number of 'i' is %d\n", i);
printf("The total number of 'o' is %d\n", o);
printf("The total number of 'u' is %d\n\n", u);
return 0;
}
Code:
/*count capital letters*/
#include <stdio.h>
int main()
{
int i, count=0;
char sentence[800];
printf("Please input text: ", stdout);
fgets(sentence, 800, stdin);
sentence[strlen(sentence)-1]='\0';
for(i=0;i<strlen(sentence);i++){
if(sentence[i]>='A'&&sentence[i]<='Z')
count++;
}
printf("\nThe total number of capital letters is %d\n\n",count);
return 0;
}
Code:
/*reverse text*/
#include <stdio.h>
#include <string.h>
int main()
{
char plain[800], cipher[800];
int i, len;
printf("Please input text: ", stdout);
fgets(plain, 800, stdin);
plain[strlen(plain)-1] = '\0';
len = strlen(plain);
for (i=0; i<len; i++)
cipher[i] = plain[len-i-1];
cipher[len] = '\0';
printf("\nThe result is: %s\n\n", cipher);
return 0;
}
Code:
/*capitalize 1st char*/
#include <stdio.h>
#include <string.h>
int main()
{
char sentence[800];
int i;
printf("Please input text: ", stdout);
fgets(sentence, 800, stdin);
if ((sentence[0] >= 'a') && (sentence[0] <= 'z'))
sentence[0] = sentence[0] - 'a' + 'A';
for (i=1; i<strlen(sentence); i++)
if ((sentence[i-1] == ' ') && (sentence[i] >= 'a') && (sentence[i] <= 'z'))
sentence[i] = sentence[i] - 'a' + 'A';
else if ((sentence[i-1] != ' ') && (sentence[i] >= 'A') && (sentence[i] <= 'Z'))
sentence[i] = sentence[i] - 'A' + 'a';
printf("\nThe result is: %s\n\n", sentence);
return 0;
}
PLEASE HELP ME!!!