Gamestudio Links
Zorro Links
Newest Posts
Zorro 2.70
by jcl. 09/29/25 09:24
optimize global parameters SOLVED
by dBc. 09/27/25 17:07
ZorroGPT
by TipmyPip. 09/27/25 10:05
assetHistory one candle shift
by jcl. 09/21/25 11:36
Plugins update
by Grant. 09/17/25 16:28
AUM Magazine
Latest Screens
Rocker`s Revenge
Stug 3 Stormartillery
Iljuschin 2
Galactic Strike X
Who's Online Now
4 registered members (NewbieZorro, Grant, TipmyPip, AndrewAMD), 12,885 guests, and 5 spiders.
Key: Admin, Global Mod, Mod
Newest Members
krishna, DrissB, James168, Ed_Love, xtns
19168 Registered Users
Previous Thread
Next Thread
Print Thread
Rate Thread
reading file name strings from a file to an array #301399
12/10/09 08:47
12/10/09 08:47
Joined: Jul 2009
Posts: 40
E
enrike Offline OP
Newbie
enrike  Offline OP
Newbie
E

Joined: Jul 2009
Posts: 40
hi

i need to read a list of file names from a txt file into an array. i am getting some weird error i think it is caused by me not understanding properly how to deal with pointers. This is the code :

///////////////
STRING* cabezaSkins[10];

filehandle = file_open_read("skins_cabeza_cfg.txt");
if (filehandle != 0)
{
STRING* file = "";
var i;
for (i = 0; i < 10; i++)
{
file_str_read(filehandle, file);
cabezaSkins[i] = file;
}
}
file_close(filehandle);
//////////////////////////

when the loop finishes all files are the same as the last one. It seems to me that when I do cabezaSkins[i] = file; they point to the same part of memory (file pointer). I need to get the actual string which is different in each loop into its array position. I tried doing str_cpy(cuerpoSkins[i], file); but this crashes the appplication on startup.

So the question is, how do i get the actuall string out of the STRING* pointer and copy it into another pointer, or better into a position inside an array of string pointers?

is there any tutorial on this kind of issues, i find strings and arrays of pointers really confusing. I have done some C++ recently but not enough i guess.

thanks

enrike

Last edited by enrike; 12/10/09 08:59.
Re: reading file name strings from a file to an array [Re: enrike] #301409
12/10/09 10:41
12/10/09 10:41
Joined: Jul 2009
Posts: 40
E
enrike Offline OP
Newbie
enrike  Offline OP
Newbie
E

Joined: Jul 2009
Posts: 40
ok. i found the solution. first i need to initialise the array items inside a function, otherwise it crashes
http://www.opserver.de/ubb7/ubbthreads.php?ubb=showflat&Number=301401#Post301401

then, of course!, i need to do
str_cpy(cuerpoSkins[i], file);
instead of
cuerpoSkins[i]= file;

Re: reading file name strings from a file to an array [Re: enrike] #301421
12/10/09 12:46
12/10/09 12:46
Joined: Feb 2008
Posts: 3,232
Australia
EvilSOB Offline
Expert
EvilSOB  Offline
Expert

Joined: Feb 2008
Posts: 3,232
Australia
Dunno if it is c-script friendly or not, but try looking in
the manual under txt_load( TEXT*,STRING* filename).

May be able to save some coding...


"There is no fate but what WE make." - CEO Cyberdyne Systems Corp.
A8.30.5 Commercial

Gamestudio download | 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