473,320 Members | 1,572 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

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*
Dec 10 '07 #1
3 2267
You could create a static const char * array for each menu category, then use a for loop to populate them.

Max
Dec 10 '07 #2
weaknessforcats
9,208 Expert Mod 8TB
You should also be able to:
Expand|Select|Wrap|Line Numbers
  1. char breadmenu[breads][menumax+1] =
  2. {"Parmasan","Gralic","Black Papper","Almond"};
  3.  
Dec 11 '07 #3
OMG thank you!!! you saved move like 20 lines!
Dec 12 '07 #4

Sign in to post your reply or Sign up for a free account.

Similar topics

27
by: Mike MacSween | last post by:
Some of my users are getting 'Disk or Network Errors'. I've raised it with the network admins, they're looking into it. In the meantime... My 'standard' error handlers logs errors to a table...
8
by: ben | last post by:
i have a bit of code, that works absolutely fine as is, but seems over complicated/long winded. is there anyway to shorten/simplify it? the code is below. description of it: it's like strcpy in...
24
by: John Smith | last post by:
I want to shorten a string by replacing the last character by '\0'. The following code displays the string. It works fine. It's in a loop and different strings are displayed without problems....
3
by: neoswf | last post by:
hi. i want to shorten getElementById() string at my files. ive writen this function: function gebi(el){ document.getElementById(el) } and when i try to call an ID, i try to call him like this:...
3
by: UKuser | last post by:
Hi, Is there a way to shorten this line if ((ereg(".jpg",$filename))||(ereg(".eps",$filename))||(ereg(".tif", $filename))||(ereg(".tiff",$filename))||(ereg(".jpeg",$filename))||...
5
by: Dean | last post by:
Hi, I have a table with non-unique identifiers. I need to take all the values with the same ID's and combine them into one field with a semicolon as a seperator. These values may exceed 255...
5
by: harryajh | last post by:
I need to output some standard text (" : *" i.e. space colon space asterisk) in loads of places in my XSLT document which outputs XHTML in XML format. The best way (several articles recommend...
1
by: treeguy | last post by:
I am not a developer but my site has long URL strings that have problem getting crawled. I understand Google now will crawl past the + but does not like the long strings. I tried URL rewrite and it...
7
by: K Viltersten | last post by:
I'm using the code below. I know for sure that the data obtained will be a single value. Hence, it feels somewhat like nuking a fly to use the adapter etc. Is it possible to shorten the code for...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.