View unanswered posts | View active topics It is currently Wed Dec 19, 2018 3:10 pm



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:

Code:
fatInitDefault();


But when I then try to read a simple txt file:

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


or create and write to a txt file:

Code:
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:
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
Profile
Site Admin

Joined: Tue Aug 09, 2005 3:21 am
Posts: 1303
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 3 guests


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 SourceForge.net. Fast, secure and Free Open Source software downloads