Skip to content

Instantly share code, notes, and snippets.

@quou
Last active November 8, 2020 22:43
Show Gist options
  • Save quou/90facd90a81a7669f02fe656a6a8cf77 to your computer and use it in GitHub Desktop.
Save quou/90facd90a81a7669f02fe656a6a8cf77 to your computer and use it in GitHub Desktop.
Load text file using PhysFS
PHYSFS_init(NULL);
PHYSFS_mount("Data.zip "/", 1);
const char* filePath = "Data/testFile.txt";
PHYSFS_file* file = PHYSFS_openRead(filePath);
if (file == NULL) {
printf("Failed to load file: %s.\n", filePath);
abort();
}
size_t fileSize = PHYSFS_fileLength(file);
char* buffer = (char*)malloc(fileSize + 1);
size_t bytesRead = PHYSFS_readBytes(file, buffer, fileSize);
buffer[bytesRead] = '\0';
PHYSFS_close(file);
// Print the text
printf("%s\n", buffer);
// Clean up
free(buffer);
PHYSFS_unmount("Data.zip");
PHYSFS_deinit();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment