menus and strings

This is a discussion on menus and strings within the C Programming forums, part of the General Programming Boards category; I have an assignment to have user enter 10 strings and then create menu to -print original strings -print string ...

  1. #1
    Registered User
    Join Date
    Apr 2002
    Posts
    5

    Question menus and strings

    I have an assignment to have user enter 10 strings and then create menu to
    -print original strings
    -print string in ASCII order
    -print strings in order of increasing length
    -print strings in order of length of first word

    This is how far I have gotten, I cannot figure out the last three. Any help would be appreciated.

    Thanks,
    #include <stdio.h>
    int main()
    {
    char message1[80], message2[80], message3[80], message4[80 message5[80];
    char message6[80], message7[80], message8[80], message9[80 message10[80];
    int opselect;
    printf("Enter a string:\n");
    gets(message1);
    printf("Enter another string:\n");
    gets(message2);
    printf("Enter another string:\n");
    gets(message3);
    printf("Enter another string:\n");
    gets(message4);
    printf("Enter another string:\n");
    gets(message5);
    printf("Enter another string:\n");
    gets(message6);
    printf("Enter another string:\n");
    gets(message7);
    printf("Enter another string:\n");
    gets(message8);
    printf("Enter another string:\n");
    gets(message9);
    printf("Enter another string:\n");
    gets(message10);

    printf("Enter a select code:");
    printf("\n 1 To display all strings input");
    printf("\n 2 To display the strings in ASCII order");
    printf("\n 3 To display the strings in order of increasing length");
    printf)"\n 4 To display the strings in order of the length of the first word in the string");
    printf("\n 5 Quit");
    scanf("%d", &opselect);
    switch (opselect)
    {
    case 1:
    printf("your messages are :\n");
    puts(message1);
    puts(message2);
    puts(message3);
    puts(message4);
    puts(message5);
    puts(message6);
    puts(message7);
    puts(message8);
    puts(message9);
    puts(message10);
    break;
    case 2:

    return 0;

    }

  2. #2
    ATH0 quzah's Avatar
    Join Date
    Oct 2001
    Posts
    14,826
    Yikes man! You need to learn what a multidimensional array is, and what a for() loop is!

    char messages[NUMBER_OF_MESSAGES][MESSAGE_LENGTH];
    int x;

    for( x = 0; x < NUMBER_OF_MESSAGES; x++ )
    {
    ... scan message into "messages[x]", or print message
    }

    You can print the messages like:

    printf("%s", messages[x] );

    Quzah.
    Hope is the first step on the road to disappointment.

  3. #3
    Disagreeably Disagreeable
    Join Date
    Aug 2001
    Posts
    711
    Look up the functions in string.h.

  4. #4
    Registered User
    Join Date
    Apr 2002
    Posts
    5
    Thanks,
    I think I have the input straightened out. Here is my new code:#include <stdio.h>
    int main()
    {
    char messages[number_of_messages][message_length];

    int opselect;
    int x;

    for( x = 0; x < NUMBER_OF_MESSAGES; x++ )

    {

    printf("Enter a string:\n");
    scanf("%c",&messages[x]);
    }

    printf("Enter a select code:");
    printf("\n 1 To display all strings input");
    printf("\n 2 To display the strings in ASCII order");
    printf("\n 3 To display the strings in order of increasing length");
    printf)"\n 4 To display the strings in order of the length of the first word in the string");
    printf("\n 5 Quit");
    scanf("%d", &opselect);
    switch (opselect)
    {
    case 1:
    for(x=0; x <=10;++i}
    printf("\n %s",messages[x]
    break;
    case 2:


    return 0;

    }

    My next question is this ASCII order? What is this?

    Thanks,

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. An error is driving me nuts!
    By ulillillia in forum C Programming
    Replies: 5
    Last Post: 04-04-2009, 09:15 PM
  2. New Project, text game, design stage.
    By Shamino in forum Game Programming
    Replies: 9
    Last Post: 05-23-2007, 06:39 AM
  3. Using Pointers With Strings
    By bobthebullet990 in forum C Programming
    Replies: 2
    Last Post: 02-14-2006, 05:28 AM

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