shorten the string variable?

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • moomooboy
    New Member
    • Dec 2007
    • 2

    shorten the string variable?

    guys please help me T_T
    im currently stuck on string, it takes too many line.
    here is my sample:

    char breadmenu[breads][menumax+1];
    strcpy (breadmenu[0],"Parmasan") ;
    strcpy (breadmenu[1],"Gralic");
    strcpy (breadmenu[2],"Black Papper");
    strcpy (breadmenu[3],"Almond");

    char meatmenu[meats][menumax+1];
    strcpy (meatmenu[0],"Chicken Steak");

    and so on.... i have like 20 or 30 of these. im just wondering if there is anyway to shorten it.
    i know tha in 2 dimensional array we can always do like this:

    int x[2][3] = {{1,2,3},{4,5,6 }}
    but i do not know if it can be apply to my question

    thanks in advance *sob*
  • mschenkelberg
    New Member
    • Jun 2007
    • 44

    #2
    You could create a static const char * array for each menu category, then use a for loop to populate them.

    Max

    Comment

    • weaknessforcats
      Recognized Expert Expert
      • Mar 2007
      • 9214

      #3
      You should also be able to:
      [code=cpp]
      char breadmenu[breads][menumax+1] =
      {"Parmasan","Gr alic","Black Papper","Almond "};
      [/code]

      Comment

      • moomooboy
        New Member
        • Dec 2007
        • 2

        #4
        OMG thank you!!! you saved move like 20 lines!

        Comment

        Working...