Gamestudio Links
Zorro Links
Newest Posts
AlpacaZorroPlugin v1.3.0 Released
by kzhao. 05/22/24 13:41
Free Live Data for Zorro with Paper Trading?
by AbrahamR. 05/18/24 13:28
Change chart colours
by 7th_zorro. 05/11/24 09:25
Data from CSV not parsed correctly
by dr_panther. 05/06/24 18:50
AUM Magazine
Latest Screens
The Bible Game
A psychological thriller game
SHADOW (2014)
DEAD TASTE
Who's Online Now
2 registered members (dr_panther, AndrewAMD), 706 guests, and 9 spiders.
Key: Admin, Global Mod, Mod
Newest Members
lorikob361, LucasJoshua, Baklazhan, Hanky27, firatv
19054 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 | 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