Gamestudio Links
Zorro Links
Newest Posts
Blobsculptor tools and objects download here
by NeoDumont. 03/28/24 03:01
Issue with Multi-Core WFO Training
by aliswee. 03/24/24 20:20
Why Zorro supports up to 72 cores?
by Edgar_Herrera. 03/23/24 21:41
Zorro Trader GPT
by TipmyPip. 03/06/24 09:27
VSCode instead of SED
by 3run. 03/01/24 19:06
AUM Magazine
Latest Screens
The Bible Game
A psychological thriller game
SHADOW (2014)
DEAD TASTE
Who's Online Now
3 registered members (AndrewAMD, TipmyPip, Edgar_Herrera), 804 guests, and 4 spiders.
Key: Admin, Global Mod, Mod
Newest Members
sakolin, rajesh7827, juergen_wue, NITRO_FOREVER, jack0roses
19043 Registered Users
Previous Thread
Next Thread
Print Thread
Rate Thread
Page 2 of 2 1 2
Re: Displaying an array of strings. [Re: tagimbul] #458829
04/01/16 15:14
04/01/16 15:14
Joined: Jun 2007
Posts: 1,337
Hiporope and its pain
txesmi Offline
Serious User
txesmi  Offline
Serious User

Joined: Jun 2007
Posts: 1,337
Hiporope and its pain
Yes, you can use array with [] but you need to create strings with str_create.

Code:
array[0] = str_create ( "First string" );
array[1] = str_create ( "Second string" );
...
str_cpy ( array[1], "..." );
// or
str_cpy ( *(array + 1), "..." );
...
str_remove ( array[0] );
str_remove ( array[1] );
...
sys_free ( array );



Salud!

Re: Displaying an array of strings. [Re: txesmi] #458831
04/01/16 15:41
04/01/16 15:41
Joined: Jan 2006
Posts: 968
EpsiloN Offline
User
EpsiloN  Offline
User

Joined: Jan 2006
Posts: 968
I suggest you read "The C Programming Language" by K&R and you'll understand pointers and other complex stuff.

You can use a pointer like "temp[5]" or "temp + 5" which is the same thing when you're dealing with a pointer, that's why you need to read the book laugh its amazing.


Extensive Multiplayer tutorial:
http://mesetts.com/index.php?page=201
Re: Displaying an array of strings. [Re: EpsiloN] #458835
04/01/16 21:04
04/01/16 21:04
Joined: Apr 2007
Posts: 3,751
Canada
WretchedSid Offline
Expert
WretchedSid  Offline
Expert

Joined: Apr 2007
Posts: 3,751
Canada
5[temp] also works. In any case though, a more modern book on C might be better to get people into the language, the R of K&R died in 2011 and the book is from 1988!


Shitlord by trade and passion. Graphics programmer at Laminar Research.
I write blog posts at feresignum.com
Re: Displaying an array of strings. [Re: WretchedSid] #458841
04/02/16 14:36
04/02/16 14:36
Joined: Jun 2010
Posts: 212
tagimbul Offline
Member
tagimbul  Offline
Member

Joined: Jun 2010
Posts: 212
i have it thx^^

Code:
#include <acknex.h>
#include <default.c>

var* alloziiere_2()
{
	var j = 10;
	return (sys_malloc(sizeof(var) * j));	
}
var *Dialogue_Nummer;

function main ()
{
	
	Dialogue_Nummer = alloziiere_2 ();
 
	Dialogue_Nummer[1] = 123;
	while(1)
	{
	DEBUG_VAR(Dialogue_Nummer[1] , 34);
	wait(1);
	}
}



meine website mit 3dgs sachen =) //noch nicht ganz umgebaut ^^"
http://flashbreaker.com/home.html
und mein YT channel mit diversen game entwicklungs videos, vor allem shader zeugs
https://www.youtube.com/user/tagimbul/videos
Re: Displaying an array of strings. [Re: tagimbul] #458842
04/02/16 14:42
04/02/16 14:42
Joined: Jun 2010
Posts: 212
tagimbul Offline
Member
tagimbul  Offline
Member

Joined: Jun 2010
Posts: 212
oh and with string:


Code:
#include <acknex.h>
#include <default.c>

STRING **str_Dialogue_Array;
STRING* alloziiere_1()
{
	var i = 10;
	return malloc(sys_malloc (sizeof(STRING*) * i));	
}

function main()
{
str_Dialogue_Array = alloziiere_1();

str_Dialogue_Array[i] = str_create("");

}



its a global initalized String array with dynamic size ^^ <3


meine website mit 3dgs sachen =) //noch nicht ganz umgebaut ^^"
http://flashbreaker.com/home.html
und mein YT channel mit diversen game entwicklungs videos, vor allem shader zeugs
https://www.youtube.com/user/tagimbul/videos
Re: Displaying an array of strings. [Re: tagimbul] #458843
04/02/16 16:17
04/02/16 16:17
Joined: Apr 2007
Posts: 3,751
Canada
WretchedSid Offline
Expert
WretchedSid  Offline
Expert

Joined: Apr 2007
Posts: 3,751
Canada
That code does not even remotely do what you think it does. For starters, array indices start at 0 and not at 1. But even worse, malloc(sys_malloc(...)) is absolutely nonsensical, use either one or the other! Both allocate memory and return a pointer to it, so by feeding the result of sys_malloc() to malloc() means you tell malloc() to allocate a memory chunk the size of whatever value the pointer has, so you might be easily allocating a gigabyte or more here. And on top of that, you leak the memory returned by sys_malloc() (obviously only a tiny a fraction of what the malloc() could potentially allocate)


Shitlord by trade and passion. Graphics programmer at Laminar Research.
I write blog posts at feresignum.com
Re: Displaying an array of strings. [Re: WretchedSid] #458844
04/02/16 16:29
04/02/16 16:29
Joined: Jun 2010
Posts: 212
tagimbul Offline
Member
tagimbul  Offline
Member

Joined: Jun 2010
Posts: 212
oh sorry i mean
Code:
return (sys_malloc (sizeof(var*) * i));	
//and
return (sys_malloc (sizeof(STRING*) * i));



that was a typo


meine website mit 3dgs sachen =) //noch nicht ganz umgebaut ^^"
http://flashbreaker.com/home.html
und mein YT channel mit diversen game entwicklungs videos, vor allem shader zeugs
https://www.youtube.com/user/tagimbul/videos
Page 2 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