View Full Version : Look-Up Table
amateurrobotguy
02-03-2005, 18:54
Would this concept be valid:
table(1)=5;
i=1
j=0
j=table(i);
"J"should return 5.
In BASIC, I would have to set the start to be 0, use a dim to se ther range to X. Is this necessary in C?
Thanks In Advance
table(1)=5;
i=1
j=0
j=table(i);
"J"should return 5.
Could you please give more detailed examples next time?
At least show all variable declarations and functions with the important algorithm chopped off.
I'm sorry, but the code pieces you show aren't detailed enough (they don't show types or declarations -- just use bogus numbers or something)
I assume what you have in the code is something like:
/* Make sure to initialize your array. */
/* int variable[LENGTH]={val1,val2,val3,...} */
int table[10]={3,2,1,6,5,4,9,8,7,0};
void myfunction (void) {
int i=1;
int j=0;
j=table[i]; // Will give you "2", not "3": indicies start at 0, not 1
// Was that your question?
}
amateurrobotguy
02-03-2005, 20:01
Yes, I believe that was my answer. I assume that I can delacre my array outside all functions and have it available everywhere too. My example would work in Basic(hopefully) :)
amateurrobotguy
03-03-2005, 18:00
Is this the proper format then for a table:
rom const int table[5]={1,
2,
3,
4,
5};
Will the multiple lines confuse it?
Dave Scheck
03-03-2005, 18:19
Will the multiple lines confuse it?C compilers ignore whitespace, so you should be fine.
vBulletin® v3.6.4, Copyright ©2000-2017, Jelsoft Enterprises Ltd.