Gamestudio Links
Zorro Links
Newest Posts
Help with plotting multiple ZigZag
by degenerate_762. 04/30/24 23:23
M1 Oversampling
by 11honza11. 04/30/24 08:16
Trading Journey
by howardR. 04/28/24 09:55
Zorro Trader GPT
by TipmyPip. 04/27/24 13:50
Data from CSV not parsed correctly
by jcl. 04/26/24 11:18
Why Zorro supports up to 72 cores?
by jcl. 04/26/24 11:09
AUM Magazine
Latest Screens
The Bible Game
A psychological thriller game
SHADOW (2014)
DEAD TASTE
Who's Online Now
2 registered members (howardR, 7th_zorro), 893 guests, and 2 spiders.
Key: Admin, Global Mod, Mod
Newest Members
firatv, wandaluciaia, Mega_Rod, EternallyCurious, howardR
19050 Registered Users
Previous Thread
Next Thread
Print Thread
Rate Thread
Page 1 of 2 1 2
STRING ARRAYs ... Please Help... #421138
04/11/13 17:51
04/11/13 17:51
Joined: Nov 2008
Posts: 28
Athens, Greece
NeoJT Offline OP
Newbie
NeoJT  Offline OP
Newbie

Joined: Nov 2008
Posts: 28
Athens, Greece
Hi... (and sorry for my english).

I have problem with STRING* ARRAYs.

I want to create and Array of Strings... for example with player names.
And i have tried with...

STRING* g_player_names[50];
or
STRING g_player_names[50];
STRING* g_playername_ptr;

and command such as :

g_player_names[1] = str_create("Test_Player");

str_cpy(g_player_names[1], "Test_Player" );

g_playername_ptr = &g_player_names[1];

*g_playername_ptr = "Test_Player";

but nothing... i receive errors - crashed etc...

//--------------------
only with char* i can create-pass a text... but i want to create a STRING ARRAY.

and a second question ... how can i pass this STRING ARRAY to a FUNCTION ???
I Know that ONLY A Pointer we can pass to a function and not an array... but still nothing...

and i have this problems ( pass to function ) and with the STRUCT ARRAYS... not only for STRING Arrays...

Please Help...


Thx all for your help...

Best Regards
Dimitris.

(and sorry for my english).

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 Offline
Expert
Uhrwerk  Offline
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: Uhrwerk] #421142
04/11/13 18:14
04/11/13 18:14
Joined: Mar 2011
Posts: 3,150
Budapest
sivan Offline
Expert
sivan  Offline
Expert

Joined: Mar 2011
Posts: 3,150
Budapest
I use string arrays created runtime, I'll put here an example tomorrow. but search the forum, I remember somebody surely made an example of it not a long time ago...


Free world editor for 3D Gamestudio: MapBuilder Editor
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 Offline OP
Newbie
NeoJT  Offline 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 Offline
Expert
Uhrwerk  Offline
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:
Code:
#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: Uhrwerk] #421146
04/11/13 19:08
04/11/13 19:08
Joined: Nov 2008
Posts: 28
Athens, Greece
NeoJT Offline OP
Newbie
NeoJT  Offline OP
Newbie

Joined: Nov 2008
Posts: 28
Athens, Greece
thank you my friend... i dont know about **

* is pointer and ** is array ???

is that true ??

i tried that to my example and its worked... :-)

I can use ** for array ??? that is something that i just learned...

thx for all...


PS... can you tell me where can i find more details for that ???



THX YOU ALL...

Best Regard.
Dimitris.

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 Offline
Expert
Uhrwerk  Offline
Expert

Joined: Jan 2002
Posts: 4,225
Germany / Essen
No, that is not correct.
Code:
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: Uhrwerk] #421149
04/11/13 19:23
04/11/13 19:23
Joined: Nov 2008
Posts: 28
Athens, Greece
NeoJT Offline OP
Newbie
NeoJT  Offline OP
Newbie

Joined: Nov 2008
Posts: 28
Athens, Greece
oohhh... i see...

if we want to send a 2d array [][] we must use ***
* first pointer is for the name
* second is for the first []
* third is for the second []

this is it ???

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 Offline
Expert
WretchedSid  Offline
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
Re: STRING ARRAYs ... Please Help... [Re: NeoJT] #421151
04/11/13 19:27
04/11/13 19:27
Joined: Nov 2008
Posts: 28
Athens, Greece
NeoJT Offline OP
Newbie
NeoJT  Offline OP
Newbie

Joined: Nov 2008
Posts: 28
Athens, Greece
and aomething else...

how can i copy two arrays without memcpy(); ??
and not for loop ???

like : array_1 = array_2.

is that ok ?

thx you all.

Page 1 of 2 1 2

Moderated by  HeelX, Lukas, rayp, Rei_Ayanami, Superku, Tobias, TWO, VeT 

Gamestudio download | chip programmers | Zorro platform | shop | Data Protection Policy

oP group Germany GmbH | Birkenstr. 25-27 | 63549 Ronneburg / Germany | info (at) opgroup.de

Powered by UBB.threads™ PHP Forum Software 7.7.1