Gamestudio Links
Zorro Links
Newest Posts
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
1 registered members (Ayumi), 662 guests, and 3 spiders.
Key: Admin, Global Mod, Mod
Newest Members
Hanky27, firatv, wandaluciaia, Mega_Rod, EternallyCurious
19051 Registered Users
Previous Thread
Next Thread
Print Thread
Rate Thread
help!! problem with arrays and reading from a file #309691
02/10/10 18:10
02/10/10 18:10
Joined: Jan 2010
Posts: 23
D
Darkmax Offline OP
Newbie
Darkmax  Offline OP
Newbie
D

Joined: Jan 2010
Posts: 23
sorry for my bad english
i´m trying to make a application to read from a text file like this:

No. Models: 3

1: soldier.mdl
id: 5

2: tank.mdl
id: 3

3: gun.mdl
id: 9

But also could be another quantity of models.

once the program read the file i want to create two arrays of strings with the size of number of models(i.e. two arrays of 3 strings for the last text file) to save in one the name of the model and in the other one the id of each model.

for example the final result will be:

array models
0 - solider.mdl
1 - tank.mdl
2 - gun.mdl

array of ids
0 - 5
1 - 3
2 - 9

i can do this very easy in c++ but in lite-c i´m having a lot of troubles.

if someone can give me some tips to do this?

Re: help!! problem with arrays and reading from a file [Re: Darkmax] #309693
02/10/10 18:29
02/10/10 18:29
Joined: Mar 2009
Posts: 112
Germany
K
KDuke Offline
Member
KDuke  Offline
Member
K

Joined: Mar 2009
Posts: 112
Germany
How about structs? That would be somewhat handier than having two (or maybe later on more) single arrays.

Here's some example:

Code:
struct MyWhatever {
  STRING* modelname;
  int id;
} MyWhatever;

MyWhatever MyArray[50];

MyArray[0].modelname = str_create("Hello World");
MyArray[0].id = 2;



Hope this helps you.

greetings
K-Duke


Using A7 Free
Click and join the 3dgs irc community!
Room: #3dgs
Re: help!! problem with arrays and reading from a file [Re: Darkmax] #309694
02/10/10 18:30
02/10/10 18:30
Joined: Jan 2003
Posts: 4,615
Cambridge
Joey Offline
Expert
Joey  Offline
Expert

Joined: Jan 2003
Posts: 4,615
Cambridge
if you can do this very easy in c++ then it should be no problem for you to rewrite it in plain c.

look up file_open_read, file_str_readto, file_var_read. this should give you the input. and instead of using the new[] and delete[] operators for arrays (or a std::list), have a look at one of the dynamic array implementations in the lite-c contributions forum (e.g. i have written one some time ago). you can allocate strings with str_create and (single) vars with
var* newvar = (var*)malloc(sizeof(var));

joey.


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