Jump to content

  • Log In with Google      Sign In   
  • Create Account

Physfs tutorial


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
3 replies to this topic

#1 falconmick   Members   -  Reputation: 80

Like
0Likes
Like

Posted 20 March 2012 - 07:26 AM

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?

Sponsor:

#2 falconmick   Members   -  Reputation: 80

Like
0Likes
Like

Posted 20 March 2012 - 07:55 AM

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?

#3 DvDmanDT   Members   -  Reputation: 893

Like
2Likes
Like

Posted 20 March 2012 - 09:14 AM

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.

#4 falconmick   Members   -  Reputation: 80

Like
0Likes
Like

Posted 20 March 2012 - 09:32 AM

null terminator at the end worked.. Thank you very much




Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS