Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

Help me implement a look up table in C

Status
Not open for further replies.

nrmlguru0308

Newbie level 2
Newbie level 2
Joined
May 19, 2010
Messages
2
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,281
Activity points
1,294
Hello,

In one of my application I need to implement a look up table in C.

I have attache the lookup table.

I need to pick the data depending on two variable parameters x and y.

for exaple if x=10 and y=4 then I have to pick 32.

Thanks in advance
 

Re: Look up table in C



You may check this

Code:
#define NUMBER_OF_ROWS 5
#define NUMBER_OF_COLS  4

static int myArray[NUMBER_OF_ROWS][NUMBER_OF_COLS] =
{
{5, 10, 15, 20},
{12, 10, 8, 8},
{24, 22, 20, 18},
{34, 32, 30, 29},
{46, 43, 43, 43}
};

void main(void)
{ int i, j;
printf("\n The contents of myArray are:\n");
for (i = 0; i < NUMBER_OF_ROWS; i++)
{ for(j = 0; j < NUMBER_OF_COLS; j++)
printf("%5d", myArray[i][j]);
printf("\n");
}
}

But, since your rows and colums are not in sequence, so you may have either full lookup table (10 rows, 20 colums) or you need to divide your X and Y by specific value (rows divide by 2, colums divide by 5) to access the table


regards
bassa
 

Re: Look up table in C

since ur index is periodic u can use following statement....
myArray[(x/5) - 1][(y/2) - 1];
ur x will have value 5, 10, 15, 20
& y will have value 2, 4, 8, 10

LookUp table will be like this
code unsigned char myArray[][] = {
{ 46, 34, 24, 12 },
{ 43, 32, 22, 10 },
{ 43, 30, 20, 8 },
{ 43, 29, 18, 8 }
};
 

Re: Look up table in C

Thanks a lot guys.....

Added after 34 minutes:

Hello Guys,

If the index is not periodic then do i need to use enum?

If for example
x values are 0,5,10,20,25,30
y values are 50,60,70,80,90,95

Thanks in advance,
 

Status
Not open for further replies.

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top