Calculator Community > Calculator C
Lists in C
(1/1)
apcalc:
Hi. I am having trouble writing a program in C for the TI-89. I am very new to the language and I still have a lot to learn.
In TI-Basic, I have programs that can take a list, ex: {1,4,3,1,7,9}, and will retrive a certain element from the list. For example, if I called for element number 2, the function would return 4.
Is there any way I can get the same feature in C. Would I use "lists" like in TI-Basic, or is there a different method. Also, I would have the lists pre-entered in the program. The program would not have to add data to the lists.
bwang:
Lets say I want a list of integers, length 6.
I'd declare it like so:
--- Code: ---int list[6] = {1, 4, 4, 1, 7, 9}
--- End code ---
and I'd access the 2nd element with:
--- Code: ---list[1]
--- End code ---
since arrays in C are indexed from 0.
apcalc:
I have another problem with lists in C. How to I add strings to a list? For example, I want the list
--- Code: ---testlist[4]={"Test","List","Hello","World"};
--- End code ---
How would I create this list. I tried declaring it as a character:
--- Code: ---char testlist[4]={"Test","List","Hello","World"};
--- End code ---
but this did not work. What am I doing wrong? Thanks again for your help! :)
bwang:
char* testlist[4] is the declaration you need, I believe.
Navigation
[0] Message Index
Go to full version