View unanswered posts | View active topics It is currently Thu Jan 24, 2019 12:46 am

Reply to topic  [ 2 posts ] 
 How to read a file? 
Author Message

Joined: Tue Apr 03, 2018 3:41 pm
Posts: 1
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:

File *fp = fopen("fat:/pyramid.txt", "rb");
//reading file contents...

or create and write to a txt file:

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:

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)?

Sat Apr 07, 2018 12:50 pm
Site Admin

Joined: Tue Aug 09, 2005 3:21 am
Posts: 1322
Location: UK
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

devkitPro IRC support
Personal Blog

Tue Jun 12, 2018 3:23 pm
Profile ICQ WWW
Display posts from previous:  Sort by  
Reply to topic   [ 2 posts ] 

Who is online

Users browsing this forum: No registered users and 1 guest

You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
  Powered by phpBB® Forum Software © phpBB Group
Designed by ST Software.
Get devkitPro at Fast, secure and Free Open Source software downloads