How to read a file?

Post Reply
mentor
Posts: 1
Joined: Tue Apr 03, 2018 3:41 pm

How to read a file?

Post by mentor » 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:

Code: Select all

fatInitDefault();
But when I then try to read a simple txt file:

Code: Select all

File *fp = fopen("fat:/pyramid.txt", "rb");
//reading file contents...
or create and write to a txt file:

Code: Select all

File *log = fopen("fat:/log.txt", "wb");
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:

Code: Select all

f32 v[18][3];
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)?

WinterMute
Site Admin
Posts: 1986
Joined: Tue Aug 09, 2005 3:21 am
Location: UK
Contact:

Re: How to read a file?

Post by WinterMute » Tue Jun 12, 2018 3:23 pm

We advise not to use explicit device strings for file IO because they're not portable and subject to change.

Unfortunately Dolphin doesn't emulate SD cards for gamecube although it will for wii but you'll need to make an SD card image and place it in the right place.

What kind of hardware setup are you currently testing with?
Help keep devkitPro toolchains free, Donate today

Personal Blog

Post Reply

Who is online

Users browsing this forum: No registered users and 0 guests