|
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
Serious User
|
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.
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
User
|
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 its amazing.
|
|
|
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
Expert
|
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: tagimbul]
#458842
04/02/16 14:42
04/02/16 14:42
|
Joined: Jun 2010
Posts: 212
tagimbul
Member
|
Member
Joined: Jun 2010
Posts: 212
|
oh and with string:
#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
|
|
|
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
Expert
|
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
Member
|
Member
Joined: Jun 2010
Posts: 212
|
oh sorry i mean
return (sys_malloc (sizeof(var*) * i));
//and
return (sys_malloc (sizeof(STRING*) * i));
that was a typo
|
|
|
|