string arrays

Posted By: MPQ

string arrays - 07/03/13 23:22

hi,

is it possible to initialize string arrays such as:

STRING *myString[2] = { "a", "b"};

this example throws an error message, but is there any way I can get this workin?
Posted By: Anonymous

Re: string arrays - 07/03/13 23:23

Use the string array build into the TEXT* object.. Look up TEXT in engine objects in the manual.

Take a look at how it was used here http://www.opserver.de/ubb7/ubbthreads.php?ubb=showflat&Number=424023#Post424041

It also sound right to make a array of pointers and fill it later.

Code:
STRING* array_strings[1000];

function this_func()
{ var x;
   for(x=0;x<1000;x++)
      { 
         array_strings[x] = str_create(" Some Text");

       }
}



Posted By: MPQ

Re: string arrays - 07/05/13 11:36

thank you, but the I have the problem that

my_text->string = array_strings[0]

doesnt work!

Posted By: sivan

Re: string arrays - 07/05/13 11:40

you left off a 'p'

str_cpy((my_text.pstring)[7], "Test!"); // lite-C
Posted By: MPQ

Re: string arrays - 07/06/13 11:37

wow thanks thats workin fine.

hopefully my last question:
I wanna use a text array as well, such as

TEXT* my_text[2]

str_cpy((my_text[0]->pstring)[7], my_str[0]);

but I get an error message!
Posted By: Kartoffel

Re: string arrays - 07/06/13 11:40

when using TEXT like this you have to allocate memory manually (afaik) or use something like text_create (if such thing exists) because you don't really create a text object but an array of pointers.
Posted By: MPQ

Re: string arrays - 07/06/13 12:06

hmm ye I see I am tryin to figure sth out
Posted By: Uhrwerk

Re: string arrays - 07/06/13 14:02

Originally Posted By: MPQ
TEXT* my_text[2]

str_cpy((my_text[0]->pstring)[7], my_str[0]);

You have no idea what you're doing, have you?

This is wrong syntax as well as nonsense. Read about operator precendece. Don't try to create an array of texts. The text object already has an array of strings. When using text objects you have to create them with http://www.conitec.net/beta/atxt_create.htm.
Posted By: Aku_Aku

Re: string arrays - 07/06/13 14:55

Before you copy a string into a string, you have to initialize the target (if this usage of the string will be the first).
Like this:
Code:
TEXT* txt_TxtContent[16];
...
	for(inx=0; inx <16; inx++) {
		txt_TxtContent[inx] = txt_create(1,0);
	}

Posted By: Locoweed

Re: string arrays - 07/17/13 07:10

TEXT* txtGoals =
{
strings = 16;
}

TEXT* txtGoalsList =
{
string ("Whatever","Blah Blah","Oh Yeah baby!");
}

str_cpy((txtGoals.pstring)[0],"Whatever");
str_cpy((txtGoals.pstring)[1],"Blah Blah");

or

(txtGoals.pstring)[0] = (txtGoalsList.pstring)[0]; // "Whatever"

(txtGoals.pstring)[1] = (txtGoalsList.pstring)[1]; // "Blah Blah"

You know, whatever,
Later,
Loco
© 2024 lite-C Forums