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
5 registered members (Kingware, AndrewAMD, AemStones, RealSerious3D, degenerate_762), 837 guests, and 2 spiders.
Key: Admin, Global Mod, Mod
Newest Members
LucasJoshua, Baklazhan, Hanky27, firatv, wandaluciaia
19054 Registered Users
Previous Thread
Next Thread
Print Thread
Rate Thread
Page 1 of 2 1 2
Lite-C file I/O #258003
03/27/09 05:08
03/27/09 05:08
Joined: Jul 2005
Posts: 192
Orange County
S
silencer Offline OP
Member
silencer  Offline OP
Member
S

Joined: Jul 2005
Posts: 192
Orange County
A couple of questions I couldn't find answers to in the manual:

- How does one determine the end of file? (EOF)
- Do any of the ANSI I/O work with Lite-C, what do I need to include if it does?


AMD 64 x2 4400+ 2048mb DDR3200 NVidia 6800GS 256mb Soundblaster Audigy 2 A7 Commercial 7.07
Re: Lite-C file I/O [Re: silencer] #258019
03/27/09 07:34
03/27/09 07:34
Joined: Jul 2002
Posts: 4,436
Germany, Luebeck
Xarthor Offline
Expert
Xarthor  Offline
Expert

Joined: Jul 2002
Posts: 4,436
Germany, Luebeck
1)
file_var_read returns 0 if there are no futher numbers, this is a little bit "dumb" because imho its possible to have files including zeros and thus you can not only "filter" for a zero in a file_var_read return value.

file_str_read returns a -1 if the end of a file is reached.

This information was found in the mighty manual.

Re: Lite-C file I/O [Re: Xarthor] #258022
03/27/09 07:42
03/27/09 07:42
Joined: Feb 2008
Posts: 3,232
Australia
EvilSOB Offline
Expert
EvilSOB  Offline
Expert

Joined: Feb 2008
Posts: 3,232
Australia
Un-tested, may not want the "=" in the if.
Code:
if(file_seek(file_handle,0,4)>=file_length(file_handle))    printf("EOF reached");



"There is no fate but what WE make." - CEO Cyberdyne Systems Corp.
A8.30.5 Commercial
Re: Lite-C file I/O [Re: EvilSOB] #258033
03/27/09 09:12
03/27/09 09:12
Joined: Oct 2007
Posts: 5,210
İstanbul, Turkey
Quad Offline
Senior Expert
Quad  Offline
Senior Expert

Joined: Oct 2007
Posts: 5,210
İstanbul, Turkey
for ansi flie io include stdio.h


3333333333
Re: Lite-C file I/O [Re: EvilSOB] #258035
03/27/09 09:18
03/27/09 09:18
Joined: Jul 2005
Posts: 192
Orange County
S
silencer Offline OP
Member
silencer  Offline OP
Member
S

Joined: Jul 2005
Posts: 192
Orange County
Thanks guys, that is helpful.

At the moment, I have a file that has strings in a row, for example in test.txt we have:

Hello world, Hello my friend

The comma is the delimiter. I just want to put those two strings into my string array in the 0 and 1 index. But I'm not sure how to increment through the strings:

Code:
	while ( (file_str_read(fhandle, test_str)) != -1)
	{
		file_str_read(fhandle, test_str);
		dialog[count] = test_str;
		count += 1;
	}


The above doesn't seem to work. Admittedly, I haven't been using file IO in A7 very long. Thanks for any help. smile


AMD 64 x2 4400+ 2048mb DDR3200 NVidia 6800GS 256mb Soundblaster Audigy 2 A7 Commercial 7.07
Re: Lite-C file I/O [Re: silencer] #258044
03/27/09 10:25
03/27/09 10:25
Joined: Jul 2008
Posts: 1,178
England
M
MrGuest Offline
Serious User
MrGuest  Offline
Serious User
M

Joined: Jul 2008
Posts: 1,178
England
Hey, use TEXT for storing your strings

Code:
TEXT* dialog = {
	strings = 2;
}

function get_file(){
	int eof = 0;
	int count = 0;
	while(eof != -1){
		eof = file_str_read(fhandle, test_str);
		(dialog.pstring)[count] = test_str;
		count += 1;
	}
}


Hope this helps

Re: Lite-C file I/O [Re: MrGuest] #258057
03/27/09 13:22
03/27/09 13:22
Joined: Jul 2002
Posts: 4,436
Germany, Luebeck
Xarthor Offline
Expert
Xarthor  Offline
Expert

Joined: Jul 2002
Posts: 4,436
Germany, Luebeck
Take a look at MrGuests code snippet which looks good.

Now I'd like to take the time and go through your code:
Code:
(1)        while ( (file_str_read(fhandle, test_str)) != -1)
(2)	   {
(3)		  file_str_read(fhandle, test_str);
(4)  		  dialog[count] = test_str;
(5)		  count += 1;
(6)	   }

Line 1: You read from the file stored in fhandle and save it in the String test_str. Remember: test_str is now filled with the first piece of your file until the first delimiter. Now you check if the end of file is reached.
Line 3: Again you read from file. So now test_str is filled with the second piece of your file (until the second delimiter, or EOF).
And this is the point where your method is failing, because you skip the first piece.

So read/use and learn from MrGuest's code snippet.

Re: Lite-C file I/O [Re: Xarthor] #258063
03/27/09 14:25
03/27/09 14:25
Joined: Jul 2005
Posts: 192
Orange County
S
silencer Offline OP
Member
silencer  Offline OP
Member
S

Joined: Jul 2005
Posts: 192
Orange County
Thanks for the help guys.

Code:
function readfile(STRING* filename){
	
	STRING* test_str = "###";

	int count;
	int eof = 0;
	var fhandle;
	
	if ( (fhandle = file_open_read(filename) ) == 0) {
		return NULL;
	}
	
	fhandle = file_open_read (filename); // Opening file
	
	count = 0;

	while(eof != -1){
		eof = file_str_read(fhandle, test_str);
		(dialog_file.pstring)[count] = test_str;
		//dialog[count] = test_str;
		count += 1;
	}
	
	node1a = (dialog_file.pstring)[1];
	file_close(fhandle);
}


Assume there is a text array for "dialog_file" defined already.

When I do the code above, when I call node1a, it's the same string (always the last string in the file), no matter what index I call from the text array. For the life of me I can't find where the kink is. The code above seems like it should work.

Last edited by silencer; 03/27/09 14:29.

AMD 64 x2 4400+ 2048mb DDR3200 NVidia 6800GS 256mb Soundblaster Audigy 2 A7 Commercial 7.07
Re: Lite-C file I/O [Re: silencer] #258065
03/27/09 14:29
03/27/09 14:29
Joined: Jul 2002
Posts: 4,436
Germany, Luebeck
Xarthor Offline
Expert
Xarthor  Offline
Expert

Joined: Jul 2002
Posts: 4,436
Germany, Luebeck
Instead of
node1a = (dialog_file.pstring)[1]
try:
str_cpy(node1a,(dialog_file.pstring[1]);

Re: Lite-C file I/O [Re: Xarthor] #258067
03/27/09 14:33
03/27/09 14:33
Joined: Jul 2005
Posts: 192
Orange County
S
silencer Offline OP
Member
silencer  Offline OP
Member
S

Joined: Jul 2005
Posts: 192
Orange County
That doesn't seem to work either Xarthor.

This seems like a serious bug with parsing files in A7, or I really need to stop programming early in the morning. smile


AMD 64 x2 4400+ 2048mb DDR3200 NVidia 6800GS 256mb Soundblaster Audigy 2 A7 Commercial 7.07
Page 1 of 2 1 2

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