Gamestudio Links
Zorro Links
Newest Posts
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
4 registered members (degenerate_762, AbrahamR, AndrewAMD, ozgur), 667 guests, and 8 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
[solded] Problem with feof function #391118
01/08/12 17:59
01/08/12 17:59
Joined: May 2008
Posts: 257
D
djfeeler Offline OP
Member
djfeeler  Offline OP
Member
D

Joined: May 2008
Posts: 257
Hello,

I have write with the old language c to read file but the function feof have a problem. When the file is finished to be read feof crash with an error E1513. Could you tell me what's wrong djfeeler thank you in advance.

My code :

Code:
#include <acknex.h>
#include <stdio.h>

function main()
{
	FILE* file = NULL;
	int character = 0;
	
	file = fopen("text.txt","r");
	
	if(file != NULL)
	{
		character = fgetc(file); // init the current character
		
		while(!feof(file)) // continue until the end of the file
		{
			printf("%c",character); // display the character
			character = fgetc(file); // read the next character
			
			if(ferror(file))
				printf("Error in file !");
		}
		
		file_close(file);
	}
	else
	{
		printf("can't open the file !");
	}
}



Last edited by djfeeler; 01/08/12 22:48.
Re: Problem with feof function [Re: djfeeler] #391138
01/08/12 21:34
01/08/12 21:34
Joined: Jan 2002
Posts: 4,225
Germany / Essen
Uhrwerk Offline
Expert
Uhrwerk  Offline
Expert

Joined: Jan 2002
Posts: 4,225
Germany / Essen
When you open a file with stdio's fopen function you have to close it with the corresponding function fclose. file_close is game studio specific and won't work here. You're even passing a wrong parameter, namely a pointer to a FILE struct. file_close expects a handle.


Always learn from history, to be sure you make the same mistakes again...
Re: Problem with feof function [Re: Uhrwerk] #391143
01/08/12 22:48
01/08/12 22:48
Joined: May 2008
Posts: 257
D
djfeeler Offline OP
Member
djfeeler  Offline OP
Member
D

Joined: May 2008
Posts: 257
thanks for the response

the code correct is :

Code:
#include <acknex.h>
#include <stdio.h>

function main()
{
	FILE* file = NULL;
	int character = 0;
	
	file = fopen("text.txt","r");
	
	if(file != NULL)
	{
		character = fgetc(file); // init the current character
		
		while(!feof(file)) // continue until the end of the file
		{
			printf("%c",character); // display the character
			character = fgetc(file); // read the next character
			
			if(ferror(file))
				printf("Error in file !");
		}
		
		fclose(file);
	}
	else
	{
		printf("can't open the file !");
	}
}




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