How to read a file?
Posted: Sat Apr 07, 2018 12:50 pm
I tried following this tutorial: [mod edit: remove outdated tutorial link] , but the code doesn't seem to work. So, I initialise fat system using:
But when I then try to read a simple txt file:
or create and write to a txt file:
Nothing happens. I mean, like really nothing. No log file is created, and also reading pyramid.txt doesn't seem to work. And what I'm trying to do is read some vertex coordinates stored in pyramid.txt, then store them in 2d array:
And then use them to draw a model with GL_Begin(). But nothing is drawn. Before I went to reading files with devkitpro, I wrote a program in C++ alone which reads pyramid.txt, processes data stored there and stores coordinates in a 2d float array and this program works. It reads contents of pyramid.txt and fills 2d float array with numbers. Besides the tutorial I gave link to above, I also looked up filesystem example which comes with devkitpro. It looks like reading files is basically done the same way as it is in C and C++ and you just need to initialise fat system first, but that's like the only difference.
What am I doing wrong? I don't see anything wrong with my devkitpro code - since reading pyramid.txt file worked in C++, why isn't it working here? Could anyone help me or give me a solid working example of reading file for Gamecube/Wii development (because that filesystem example, although compiles successfully, doesn't show anything in emulator)?
Code: Select all
fatInitDefault();
Code: Select all
File *fp = fopen("fat:/pyramid.txt", "rb");
//reading file contents...
Code: Select all
File *log = fopen("fat:/log.txt", "wb");
Code: Select all
f32 v[18][3];
What am I doing wrong? I don't see anything wrong with my devkitpro code - since reading pyramid.txt file worked in C++, why isn't it working here? Could anyone help me or give me a solid working example of reading file for Gamecube/Wii development (because that filesystem example, although compiles successfully, doesn't show anything in emulator)?