Public Group

Physfs tutorial

This topic is 2252 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

Recommended Posts

Ok... I have a build working version of physfs... too bad I havn't the slightest of a clue on how to use it properly...

Can anyone link me to how I would add files to the .zip?

I am currently following http://icculus.org/physfs/physfstut.txt but it's kinda confusing... too bad theres no decent tutorials for this... maybe has anyone found a decent tutorial?

Share on other sites
ok.. been fiddling to learn myself, still can't exactly figure our writing data as such as .tga and other assets.. but I have run into a problem with importing...
when I use this:

 #include "physfs.h" #include <iostream> int main(int argc, char** argv) { char *myBuf; //char myBuf[33]; PHYSFS_init(argv[0]); PHYSFS_init(NULL); if(PHYSFS_addToSearchPath("test.zip", 1)) { if(PHYSFS_exists("test file in zip.txt")) { PHYSFS_file* myfile = PHYSFS_openRead("test file in zip.txt"); int fileLngth = PHYSFS_fileLength(myfile); myBuf = new char[fileLngth + 1]; int length_read = PHYSFS_read (myfile, myBuf, 1, PHYSFS_fileLength(myfile)); myBuf[fileLngth] = '\n'; std::cout << myBuf; PHYSFS_close(myfile); } else { std::cout << "error, no file found inside zip"; } } else { std::cout << "error, no zip found"; } PHYSFS_deinit(); getchar(); } 
but when I use
 PHYSFS_read 
it for some reason turns my array of 33 into a longer one with garbage data on the end ("this worked... holy shit!! YESSS!ýýýý««««««««þîþ" yes.. I did get an error with my success statement ;( fail) the "ýýýý««««««««þîþ" part shouldn't be there.. but it always is... for some reason it is gaining that garbage.

any ideas?

EDIT:
it seams that new char[X] is allocating X space for each char.. but for some reason at the end it is adding "ýýýý««««««««þîþ"

ive solved garbage on the end through manually shortening the size of the char array by 15.. I don't feel as if this is the correct solution, but atm it feels like the only..

any ideas why it did this?

Share on other sites
It's not PhysFS that adds anything, it's due to how strings work in C/C++. It's not null-terminated at the moment. You'll need to add NULL after the last char that is read. In other words, you need to allocate an array that is 1 byte larger than the file and set the last byte to 0/NULL.

EDIT: Just google null-terminated strings and I'm sure you'll understand.

Share on other sites
null terminator at the end worked.. Thank you very much

• 10
• 13
• 14
• 18
• 15