CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug reports on this forum. Send them to CCS Technical Support

Lookup Table

 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
octobersky



Joined: 21 Jun 2005
Posts: 3

View user's profile Send private message

Lookup Table
PostPosted: Wed Nov 30, 2005 2:29 pm     Reply with quote

12 combinations of 3 items from a group of six.

items: apple, pear, grape, plumb, orange, and tomato

combination 0: apple, pear, plumb
combination 1: apple, plumb, orange
..

each item has three different properties
apple = {20.1, 25.2, 30.3}
pear = {10.0, 12.5, 17.5}
..

I'm trying to write a function in C that will access one property of an item
given the combination number and item index. For example:
lookup(1,0,2) would return 30.3 or second combination, first item, third property.

I don't really know where to start
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Wed Nov 30, 2005 3:46 pm     Reply with quote

Use a three dimensional array.
octobersky



Joined: 21 Jun 2005
Posts: 3

View user's profile Send private message

3D Array
PostPosted: Wed Nov 30, 2005 4:13 pm     Reply with quote

2D (2x3)
Code:

  int grid[3][2] = { {10,20},{30,40},{50,60} };

  /* The table of grid looks like
   *    ---------
   *  0| 10 | 20 |
   *  1| 30 | 40 |
   *  2| 50 | 60 |
   *    ---------
   *      0    1
   *
   */


{ {x1y1,x2y1}, {x1y2,x2y2}, {x1y3,x2y3} }

3D (2x3x2)

Does z build out of the page?

{ {x1y1z1,x2y1z1}, {x1y2z1,x2y2z1}, {x1y3z1,x2y3z1},
{x1y1z2,x2y1z2}, {x1y2z2,x2y2z2}, {x1y3z2,x2y3z2} }

grid [1][0][1] = x1y2z2?
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group