Last active
November 8, 2020 22:43
-
-
Save quou/90facd90a81a7669f02fe656a6a8cf77 to your computer and use it in GitHub Desktop.
Load text file using PhysFS
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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