2 registered members (AndrewAMD, TipmyPip),
12,420
guests, and 5
spiders. |
Key:
Admin,
Global Mod,
Mod
|
|
|
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
CaedLucin
OP
Newbie
|
OP
Newbie
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.
<?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.
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.
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! 
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
Junior Member
|
Junior Member
Joined: Apr 2010
Posts: 56
|
I wrote the below code quickly, let me know if you have any concerns about it. #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); }
|
|
|
|