reading txt from zip

If you are a new Irrlicht Engine user, and have a newbie-question, this is the forum for you. You may also post general programming questions here.
Post Reply
Gurkenlaster

reading txt from zip

Post by Gurkenlaster »

hi, i want to load a file "Index.txt" from a zip file, the txt-file only contains one number,
I try this, but it dont work:

Code: Select all

app->device->getFileSystem()->addZipFileArchive("members.zip", true, true);
	IReadFile* Index = app->device->getFileSystem()->createAndOpenFile("index.txt");
	char* indexstr;
	Index->read ( indexstr,  1);
My App crashs ... why?
whats wrong ???
niko
Site Admin
Posts: 1759
Joined: Fri Aug 22, 2003 4:44 am
Location: Vienna, Austria
Contact:

Post by niko »

Debug it, and tell as where it exactly crashes. Its difficult to tell from this description.
Tels
Posts: 65
Joined: Fri Feb 27, 2004 7:56 pm
Location: Antarctica
Contact:

Re: reading txt from zip

Post by Tels »

Gurkenlaster wrote:hi, i want to load a file "Index.txt" from a zip file, the txt-file only contains one number,
I try this, but it dont work:

Code: Select all

app->device->getFileSystem()->addZipFileArchive("members.zip", true, true);
	IReadFile* Index = app->device->getFileSystem()->createAndOpenFile("index.txt");
	char* indexstr;
	Index->read ( indexstr,  1);
My App crashs ... why?
whats wrong ???

Your problem is here:

Code: Select all

	char* indexstr;
	Index->read ( indexstr,  1);
You have a pointer to a string, but you never allocate memory for the string buffer. Reading into it from the file will crash.

Change it to this:

Code: Select all

	char indexstr[1024];
	Index->read ( indexstr,  1);
and it should work (but will do nasty things if there is a line longer than 1024 characters in the file, so beware!.

HTH,

Tels :twisted:
Perl + Irrlicht + Audiere = Game: http://bloodgate.com/perl/game
Gurkenlaster

Post by Gurkenlaster »

Now it works, thanks! :D
Post Reply