• Welcome to Overclockers Forums! Join us to reply in threads, receive reduced ads, and to customize your site experience!

I need some 'C' help

Overclockers is supported by our readers. When you click a link to make a purchase, we may earn a commission. Learn More.

Speed_Freak

Member
Joined
Aug 10, 2001
Location
Cali
Hello, Im currently taking a C programming course. For our last project we had to make a very simple program that gave the user some choices that they could select. The chioces all had some numerical data that was totaled and printed out at the end of the proggy. It was linear and was composed of nothing but if-then statements and the like (no functions, everything was in main). Okay, so now we have to change (or in my case start over) our program so that the user can change the amount of their previous selections and call-up/display the choices and there corresponding data at any time (so basically i will keep a running total if you will). I want to use array's but I can't have characters and integers in the same array. okay, so HERE is the question. How would I be able to make a 'data table' if you will that allows me to link the names (in one array) to its numerical data (in a second array) and be able to store that info away once the user selects the items so that it can be recalled, totaled, and displayed at a later time? There are 4 seperate pieces of numerical data that go with each name I will have in the first array. Sorry if that was long but I had to explain a lot to get to that one question. I really want to be able to implement array's and several functions (it would be good practice) but i can't until i can get around that one hurdle. Thanks for the help in advance. Oh and yes my teacher said I could use ANY resource...even the oc.com forums (which he thinks is cool btw). K later.
 
well I would make two arrays that mirror each other... so Array1(i) 's value goes with Array2(i)'s value.

I'm a little tired right now so I'll write back when I'm a little more awake....
 
Two dimensional arrays?

array [nameIndex] [numberIndex]

Looks like that's what you want. Might have to have another array for the names, too.
 
I know how to do a 2 dimensional array, but that wouldn't really help me. I want to be able to simultaneously access the data in two arrays...for instance:


[array 1 names] [array 2 values]
1.) xxxxxxxxx 12345678
2.) xxxxxxxxx 12345678
3.) xxxxxxxxx 12345678
4.) xxxxxxxxx 12345678
5.) xxxxxxxxx 12345678
6.) xxxxxxxxx 12345678

Of course this is just a cheesy graphical representation. Array 1 has a big list of characters strings and array 2 will be a two-dimensional array consisting of several different numerical properties. The items in array 1 will be recalled/selected by the user through several choices and prompts provided by the program. When the user 'selects' something from the first array (say the 3rd row)i need to be able to somehow have all of numbers contained in the corresponding row be stuffed away to be added to a running total. I was just wondering if it was possible to do that or would i have to put each and every number in its own variable name (that would need about 90 variables which is why i want to use an array). Would several arrays be easier?? Sorry but im truly stumped.

Justin
 
Krieger said:
Thanks Thelemac, hat's what I was thinking of. I got stuck with doign the third shift again so my brain is mostly slag right now...

a struct perhaps?/

struct whatever
{
char text[10];
int number;

}

my code is ****, I know I havent touched c/c++ in quite some time :(

|eb_CRX
 
Metra,
That was my original thought, but what concerns me is that the second array he wants to access is 2d. I'm wondering how he will index into it with only 1 index. With the first array you can index by using array[x] but the second you will need array[x][y]. I'm just wondering where he will be getting [y] from to complete the array index...
 
whoa whoa, is this the calculator program??? ex user inputs, 2 * then 6 / .... ?? if it is i can help u out cuz im takin C also and recently did that proggy...
 
Metra,
That was my original thought, but what concerns me is that the second array he wants to access is 2d. I'm wondering how he will index into it with only 1 index. With the first array you can index by using array[x] but the second you will need array[x][y]. I'm just wondering where he will be getting [y] from to complete the array index...

Thats the thing I only need to be able to link the first array to the seconds array's entire row...I dont need to be able to pick out individuals cooridnates.
 
Couldn't you reference them with the same index?

So you'd get the index from the first array and use that to access the second?
 
Back