[solded] Problem with feof function

Posted By: djfeeler

[solded] Problem with feof function - 01/08/12 17:59

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 !");
	}
}


Posted By: Uhrwerk

Re: Problem with feof function - 01/08/12 21:34

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.
Posted By: djfeeler

Re: Problem with feof function - 01/08/12 22:48

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 !");
	}
}


© 2024 lite-C Forums