Chief Delphi

Chief Delphi (http://www.chiefdelphi.com/forums/index.php)
-   Programming (http://www.chiefdelphi.com/forums/forumdisplay.php?f=51)
-   -   Look-Up Table (http://www.chiefdelphi.com/forums/showthread.php?t=35721)

amateurrobotguy 02-03-2005 18:54

Look-Up Table
 
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

ace123 02-03-2005 19:47

Re: Look-Up Table
 
Quote:

Originally Posted by amateurrobotguy
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:
Code:

/* 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

Re: Look-Up Table
 
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

Re: Look-Up Table
 
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

Re: Look-Up Table
 
Quote:

Originally Posted by amateurrobotguy
Will the multiple lines confuse it?

C compilers ignore whitespace, so you should be fine.


All times are GMT -5. The time now is 04:41.

Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2017, Jelsoft Enterprises Ltd.
Copyright © Chief Delphi