Computing.Net > Forums > Programming > C Programming Question

C Programming Question

Reply to Message Icon

Original Message
Name: almo89
Date: November 4, 2005 at 15:22:39 Pacific
Subject: C Programming Question
OS: Windows xp mce
CPU/Ram: p3/700mhz
Comment:

Hi. I'm in a very basic C Programming class. Its defanatly for beginners so this probably will be an easy question. I have my program set as follows....The user enters 10 names into a character array using a for loop. The user picks these names from a list where there are 20 choices. (by the way i have the array declared as "char names[10][20];") Now here is the problem. I cant think of an EFFICENT way to get the results i want. I want it so that the program recognizes what name was typed in and, depending on the name that the user entered, have another integer variable changed. That might be confusing so heres an example. (Ex: name[0] = "john" so therefore "money = money+10") How can i do this? There are 20 different options, so i dont want to have like 200 "strcmp" functions. Help is SOOO greatly appreciated. Thanks.


Report Offensive Message For Removal


Response Number 1
Name: Prissy
Date: November 5, 2005 at 12:34:17 Pacific
Reply: (edit)

Use a switch statement

switch(displayarray(names[][20],SIZE))
case 'john':
money+=10;
break;

etcetera

As you see, I send the array to a function for display and get my input returned to the switch. :) HTH


Report Offensive Follow Up For Removal







Use following form to reply to current message:

   Name: From My Computing.Net Settings
 E-Mail: From My Computing.Net Settings

Subject: C Programming Question

Comments:

 


  Homepage URL (*): 
Homepage Title (*): 
         Image URL: 
 
Data Recovery Software




Have you ever used OpenOffice?

Yes, as my main suite.
Yes, occationally.
Yes, but only once.
No, never.


View Results

Poll Finishes In 5 Days.
Discuss in The Lounge