#53774 - Dannon - Sun Sep 11, 2005 8:08 pm
Is there a good tutorial for reading a text file and then displaying it, whether it be straight to the console or using a tile set for the letters?
Dannon wrote: |
A bit of both really, I know how to get to the file with the Chishm's CF Reading code but then I'm not sure on howto actually read it into memory on the DS, can I just use char* text? |
Code: |
FAT_InitFiles(); // Init FAT driver
FAT_FILE* handle = FAT_fopen("test.txt", "r"); // Open test.txt for reading FAT_fseek(handle, 0, SEEK_END); // Go to end of file u32 size = FAT_ftell(handle); // Get current position in file, because it is the end it will be the size char* text = (char*) malloc (size); // Allocate memory for file FAT_fseek(handle, 0, SEEK_SET); // Go to begining of file FAT_fread((void*)text, size, 1, handle); // Read all of file into memory FAT_fclose(handle); // Close file |
Code: |
FAT_InitFiles(); // Init FAT driver
FAT_FILE* handle = FAT_fopen("test.txt", "r"); // Open test.txt for reading u32 size = 256; // Read in 256 bytes at a time char* text = (char*) malloc (size+1); // Allocate memory for string, including end of string character text[size] = '\0'; // Add string terminate character FAT_fseek(handle, 0, SEEK_SET); // Go to begining of file while (!FAT_feof(handle) { FAT_fread((void*)text, size, 1, handle); // Read next bit of file into memory consolePrintf(text); // Print file to screen } FAT_fclose(handle); // Close file |