Menu problem, HELP!!

This is a discussion on Menu problem, HELP!! within the C Programming forums, part of the General Programming Boards category; i want to make a menu using C but after i typed all the functions included in the menu, i ...

  1. #1
    Registered User
    Join Date
    Nov 2007
    Posts
    5

    Menu problem, HELP!!

    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!!!

  2. #2
    Aia
    Aia is offline
    Beautiful to C Aia's Avatar
    Join Date
    Jun 2007
    Posts
    124
    Make a function for each of those mains corresponding to every option.

    Code:
    create a loop that will stop when user quits
        get option from user
        in a switch
            option a
                do function a
            option b
                do function b
            option c
                do function c
            option quit
                quit

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. A question related to strcmp
    By meili100 in forum C++ Programming
    Replies: 6
    Last Post: 07-07-2007, 02:51 PM
  2. Simple Menu Problem
    By DanC in forum C++ Programming
    Replies: 4
    Last Post: 03-15-2006, 12:33 PM
  3. Problem with Mouse Over Menu!!! HELP!!!
    By SweeLeen in forum C++ Programming
    Replies: 3
    Last Post: 02-09-2006, 01:10 AM
  4. Window - Menu problem...
    By FromHolland in forum Windows Programming
    Replies: 1
    Last Post: 02-26-2004, 02:49 PM
  5. MDI and MENU Problem
    By Marc in forum Windows Programming
    Replies: 3
    Last Post: 02-21-2004, 05:59 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21