copy an element of an array to a string

Posted By: msmith2468

copy an element of an array to a string - 12/21/11 19:09

i have an array. i want the contents of the array to contain a string to be displayed on the screen. i have tried two ways without luck.
The first way i made the array elements contain the contents of the string. aparently i can not do this with an array. so this led me to my second method.
My second method i defined the strings as pointers then filled the array with the pointers. but when i call the value in the array i do not get the string.


Second method.......
in this example Display should be " R E D "
___________________________________________________________
STRING* Title_0 = " Y e l l o w ";
STRING* Title_1 = " R E D ";
STRING* Title_2 = " P U R P L E ";
STRING* Title_3 = " B L U E ";

function fillin()
array[0] = Title_0;
array[1] = Title_1;
array[2] = Title_2;
array[3] = Title_3;

function DisplayStr()
current = 1;
str_cpy (Display,array[current]);
__________________________________________________________

Any help would be appreciated.
Posted By: Superku

Re: copy an element of an array to a string - 12/21/11 23:41

Normally, you create string arrays as follows:

STRING* str_array[10];
...
for(i = 0; i < 10; i++) str_array[i] = str_create("");

In your case the "array" would need to be a string array, too, how did you declare it?
Posted By: msmith2468

Re: copy an element of an array to a string - 12/22/11 00:36

That was my problem, i had array as a var. when i switch it to a string array then it worked great.

thanks a lot. i have been messing around with this for hours. i would have thought some sort of error would have popped up.

that's what i get for using python for the last 6 months where types are interchangeable.
© 2024 lite-C Forums