Gamestudio Links
Zorro Links
Newest Posts
Zorro Beta 2.61: PyTorch
by jcl. 06/10/24 14:42
New FXCM FIX Plugin
by flink. 06/04/24 07:30
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
AUM Magazine
Latest Screens
The Bible Game
A psychological thriller game
SHADOW (2014)
DEAD TASTE
Who's Online Now
1 registered members (AndrewAMD), 1,519 guests, and 8 spiders.
Key: Admin, Global Mod, Mod
Newest Members
AemStones, LucasJoshua, Baklazhan, Hanky27, firatv
19058 Registered Users
Previous Thread
Next Thread
Print Thread
Rate Thread
Help with .txt file value extraction using the file_find method #325537
05/27/10 03:15
05/27/10 03:15
Joined: May 2010
Posts: 8
Singapore
C
CaedLucin Offline OP
Newbie
CaedLucin  Offline OP
Newbie
C

Joined: May 2010
Posts: 8
Singapore
Hello there,

I'm new to the Lite C language, therefore i'm met with some problems with my school project and is hoping any kind souls out there could help me with this.

You see, I'm trying to extract some specific values from a .txt file such as the one below.

Code:
<?xml version="1.0"?>
<Song>
    <Properties>
        blah blah
        ...
        ...
        blah blah
    </Properties>

    <Data>
        <Note time="1.9375" duration="0.0" track="0" >
        </Note>
        <Note time="1.9375" duration="0.0" track="1" >
        </Note>
        <Note time="2.125" duration="0.0" track="0" >
        </Note>
        <Note time="2.125" duration="0.0" track="1" >
        </Note>
        <Note time="2.375" duration="0.0" track="0" >
        </Note>
        <Note time="2.375" duration="0.0" track="1" >
        </Note>
    </Data>
</Song>



And so right now I'm trying to extract all the "Note time" and "track" values and store them into two seperate arrays. I've just started on this, so looking through at the game manual library, I intended to use file_find to aid me on this.

And so, I've successfully extracted the first "Note time" value which is 1.9375 with the code below and first display it as text on the screen.

Code:
var filehandle;
STRING* time_str = "";
STRING* track_str = "";

TEXT* timing_txt =
{
	pos_x = 0;
	pos_y = 0;
	//string(greeting_str);
	string(time_str);
	flags = VISIBLE;
}

TEXT* track_txt =
{
	pos_x = 0;
	pos_y = 50;
	string(track_str);
	flags = VISIBLE;
}

function read_file()
{
	int eof = 0;
	while(eof != -1)
	{
		file_find(filehandle, "<Data>");
		
		file_find(filehandle, "time=\"");
		eof = file_str_readto(filehandle, time_str, "\"", 4000);	// Read till the set delimiter
	}
}

function main()
{
	video_mode = 7;
	screen_color.blue = 150;
	filehandle = file_open_read("testversion.sng");
	read_file();
	file_close(filehandle);
}



But when i try to extract the "track" value into track_str with the following updates to the codes in the read_file() function, both text values appear as 0 value on the screen.

Code:
function read_file(STRING* filename)
{
	int eof = 0;
	while(eof != -1)
	{
		file_find(filehandle, "<Data>");
		
		file_find(filehandle, "time=\"");
		eof = file_str_readto(filehandle, time_str, "\"", 4000);	// Read till the set delimiter
		
		file_find(filehandle, "track=\"");
		eof = file_str_readto(filehandle, track_str, "\"", 4000);
	}
}



Could anyone shed some light as to where did i went wrong? I believe it's my understanding of the file_find method to be the problem though. And thank you very much in advance! laugh

Last edited by CaedLucin; 05/27/10 03:19.
Re: Help with .txt file value extraction using the file_find method [Re: CaedLucin] #326266
05/31/10 13:03
05/31/10 13:03
Joined: Apr 2010
Posts: 56
Badrizmo Offline
Junior Member
Badrizmo  Offline
Junior Member

Joined: Apr 2010
Posts: 56
I wrote the below code quickly, let me know if you have any concerns about it.

Click to reveal..

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

var filehandle;
STRING* time_str = "";
STRING* track_str = "";
var eof;

var dbg_DataLocation=0;
var dbg_TimeLocation = 0;
var dbg_TrackLocation = 0;

int dbg_counter=0;

TEXT* timing_txt =
{
pos_x = 0;
pos_y = 0;
//string(greeting_str);
string(time_str);
flags = VISIBLE;
}

TEXT* track_txt =
{
pos_x = 0;
pos_y = 50;
string(track_str);
flags = VISIBLE;
}

function read_file()
{
int eof = 0;
while(eof != -1)
{
file_find(filehandle, "<Data>");

file_find(filehandle, "time=\"");
eof = file_str_readto(filehandle, time_str, "\"", 4000); // Read till the set delimiter
}
}

function read_file2()
{
eof = 0;
dbg_DataLocation = file_find(filehandle, "<Data>");

if (dbg_DataLocation>0)
{

do
{
dbg_counter+=1;

dbg_TimeLocation = file_find(filehandle, "time=\"");
if (dbg_TimeLocation>0)
{
eof = file_str_readto(filehandle, time_str, "\"", 40);
}

dbg_TrackLocation = file_find(filehandle, "track=\"");
if(dbg_TrackLocation>0)
{
eof = file_str_readto(filehandle, track_str, "\"", 40);
}
wait(1000);

}while((dbg_TimeLocation > 0)||(dbg_TrackLocation > 0));
}
}

function main()
{
video_mode = 7;
screen_color.blue = 150;
filehandle = file_open_read("testversion.sng");
read_file2();
file_close(filehandle);
}


Re: Help with .txt file value extraction using the file_find method [Re: Badrizmo] #326691
06/02/10 13:56
06/02/10 13:56
Joined: May 2010
Posts: 8
Singapore
C
CaedLucin Offline OP
Newbie
CaedLucin  Offline OP
Newbie
C

Joined: May 2010
Posts: 8
Singapore
Thank you Badrizmo, but i've already solved the problem. hehe!


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