Omnimaga

Calculator Community => TI Calculators => Calculator C => Topic started by: apcalc on May 17, 2010, 08:40:19 pm

Title: Lists in C
Post by: apcalc on May 17, 2010, 08:40:19 pm
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.
Title: Re: Lists in C
Post by: bwang on May 17, 2010, 09:00:09 pm
Lets say I want a list of integers, length 6.
I'd declare it like so:
Code: [Select]
int list[6] = {1, 4, 4, 1, 7, 9}and I'd access the 2nd element with:
Code: [Select]
list[1]since arrays in C are indexed from 0.
Title: Re: Lists in C
Post by: apcalc on May 24, 2010, 06:22:51 pm
I have another problem with lists in C.  How to I add strings to a list?  For example, I want the list

Code: [Select]
testlist[4]={"Test","List","Hello","World"};
How would I create this list.  I tried declaring it as a character:

Code: [Select]
char testlist[4]={"Test","List","Hello","World"};
but this did not work. What am I doing wrong?  Thanks again for your help! :)
Title: Re: Lists in C
Post by: bwang on May 24, 2010, 06:39:32 pm
char* testlist[4] is the declaration you need, I believe.