2 registered members (howardR, 7th_zorro),
893
guests, and 2
spiders. |
Key:
Admin,
Global Mod,
Mod
|
|
|
Re: STRING ARRAYs ... Please Help...
[Re: NeoJT]
#421139
04/11/13 17:59
04/11/13 17:59
|
Joined: Jan 2002
Posts: 4,225 Germany / Essen
Uhrwerk
Expert
|
Expert
Joined: Jan 2002
Posts: 4,225
Germany / Essen
|
Use TEXTs instead. A TEXT already contains a string array and a a plus you get several engine functions dealing with TEXT objects.
Concerning the string array you want to create: You're just wildly guessing what to do. This won't work. Have a look in the manual concerning variables and pointers. The correct way to define an array of STRING pointers is "STRING* g_player_names[50];". But don't forget this is just an array with vagabonding pointers in it.
Always learn from history, to be sure you make the same mistakes again...
|
|
|
Re: STRING ARRAYs ... Please Help...
[Re: sivan]
#421144
04/11/13 18:49
04/11/13 18:49
|
Joined: Nov 2008
Posts: 28 Athens, Greece
NeoJT
OP
Newbie
|
OP
Newbie
Joined: Nov 2008
Posts: 28
Athens, Greece
|
i want to pass a string array to a function... or a struct array... but i can only pass one string and not all array... for example :
int g_player_id = 0; STRING* g_player_name[50];
function main() { g_player_id++; g_player_name[g_player_id] = str_create("Test_1_Player"); g_player_id ++; g_player_name[g_player_id] = str_create("Test_2_Player");
f_print_name(g_player_id-1, g_player_name); wait_for(f_print_name); }
function f_print_name(int l_i, STRING* l_name) { printf("Player [ %i ] name is : %s", l_i, _chr( l_name ) ); printf("Player [ %i ] name is : %s", (l_i+1), _chr( l_name + 1 ) ); }
//------------------------------------------------------ /* i use ( l_name + 1 ) because l_name is a pointer and somewhere i read that the l_name[1] and l_name[2] i can write also as (l_name) and (l_name + 1)... also i was tried with l_name[1] and l_name[2] but nothing... the result is empty ... (means that the string values cannot pass to function)...
the same problem i have with string thas is within a struct... i cannot pass a struct array to a function... */ //------------------------------------------------------
my target is to create a function that can take string arrays or Struct arrays ( with pointers only as i know ) , edit the values and send the result back or change the global value inside that function...
(Function-Command-Parameters like as C# :
stringarray = somestring.split('-'); a function that splits a string and return the result into an array of strings... )
my function must take the array from user such as :
f_split( STRING* l_str_to, STRING* l_str_from, char* l_char_to_split);
or
STRING* l_str_to[100];
l_str_to = f_split(STRING* l_str_from, char* l_char_to_split);
//------------------------------------------ but my problem is that i cannot also pass and struct arrays... :-(
thx you all... (and sorry for my english).
Best Regards. Dimitris.
Last edited by NeoJT; 04/11/13 19:00.
|
|
|
Re: STRING ARRAYs ... Please Help...
[Re: NeoJT]
#421145
04/11/13 18:59
04/11/13 18:59
|
Joined: Jan 2002
Posts: 4,225 Germany / Essen
Uhrwerk
Expert
|
Expert
Joined: Jan 2002
Posts: 4,225
Germany / Essen
|
Again my advice: read the manual and / or a good c book. Don't try this by trial and error. This will come in very very expensive later on. And please use code tags when posting code. Here is a quick sample that should get you started anyways:
#include <acknex.h>
STRING* my_string_array[2];
void print_strings(STRING** array,int numberOfElements)
{
int i;
for (i = 0; i < numberOfElements; i++)
printf(array[i]->chars);
}
void main()
{
my_string_array[0] = str_create("Alpha");
my_string_array[1] = str_create("Bravo");
print_strings(my_string_array,2);
}
Always learn from history, to be sure you make the same mistakes again...
|
|
|
Re: STRING ARRAYs ... Please Help...
[Re: NeoJT]
#421148
04/11/13 19:16
04/11/13 19:16
|
Joined: Jan 2002
Posts: 4,225 Germany / Essen
Uhrwerk
Expert
|
Expert
Joined: Jan 2002
Posts: 4,225
Germany / Essen
|
No, that is not correct.
STRING* s = NULL; // A pointer to a string struct
STRING** s2 = NULL; // A pointer to a pointer to a string struct
STRING*** s3 = NULL; // A pointer to a pointer to a pointer ...
Keep in mind that an array is just a pointer to a memory area where the content of the array lays one element after another. I believe JustSid posted some excellent tutorial concerning pointers some time ago: http://eternallyconfuzzled.com/tuts/languages/jsw_tut_pointers.aspx
Always learn from history, to be sure you make the same mistakes again...
|
|
|
Re: STRING ARRAYs ... Please Help...
[Re: NeoJT]
#421150
04/11/13 19:27
04/11/13 19:27
|
Joined: Apr 2007
Posts: 3,751 Canada
WretchedSid
Expert
|
Expert
Joined: Apr 2007
Posts: 3,751
Canada
|
No. You can have a 2d Array with just one or two "stars". It all boils down to your data type and how you want to interpret it. If you want a 2d STRING array, you would most likely write it like STRING ***myArray. Please read the link Uhrwerk has posted, it is immensely useful!
Shitlord by trade and passion. Graphics programmer at Laminar Research. I write blog posts at feresignum.com
|
|
|
|