123
-=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- (c) WidthPadding Industries 1987 0|566|0 -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=-
Socoder -> C/C++/C#/Other -> saving/reading a long to/from a file?

Tue, 11 Dec 2007, 06:07
spinal
I am trying to save a long int to a file, then read it back, however its not working, can someone help me out?






-=-=-
Check out my excellent homepage!
Tue, 11 Dec 2007, 06:38
Jayenkai
Long int's aren't 4, are they?
I thought regular ints were 32bit = 4, and longints were 64bit=8..

Having googled it, the whole net seems confused with some saying 4 and some saying 8!
A few suggest that a "long long int" is 8!!


I think the rule might be that if and int is 4 then long should be 8. so try that!
If not.. Are you sure the DS is even handling the long as it should in the first place, even before the load/save stuff?

-=-=-
''Load, Next List!''
Tue, 11 Dec 2007, 06:52
Afr0
AFAIK, from what I've learned from my time with C and C++, the actual size of standard variables in memory can vary from machine to machine.
I'm pretty sure there's a 'standard' value for the DS though - this should be easy to print out using the sizeof() function. Not sure what headers you need to include to get that function in the DS API, but it should just be standard C headers.

(PC) Test Program:



Note that the parameters (specifically, the '%i' bit) for the fprint function might be wrong - I haven't used ANSI C for ages.

Edit: Found a better example.



-=-=-
Afr0 Games

Project Dollhouse on Github - Please fork!
Tue, 11 Dec 2007, 17:38
spinal
long is printing out as 4.

Other than the worries about the size of the variable, are my attempts logical, or am I missing something? No matter what the variable is when writing, it reads (or at least prints) as 1. perhaps I'm using fread incorrectly.

-=-=-
Check out my excellent homepage!
Tue, 11 Dec 2007, 17:43
Jayenkai
Oh yeah.. That's right.. I had weird issues trying to read 1 single thing, didn't I!
Have you tried creating a small temp[2] array, and loading into that instead? That usually works for me

-=-=-
''Load, Next List!''
Tue, 11 Dec 2007, 17:58
spinal
You'll have to give me some example code jay, do you mean I should load the 4 bytes seperatly?

-=-=-
Check out my excellent homepage!
Tue, 11 Dec 2007, 18:11
Jayenkai
I'm sure fileread should do as it says, but I can't seem to get it to work with single variables, and instead it seems insistent on working with Arrays. (I really should learn all this pointer gubbins someday!)



Where you have that, switch it with this.



And vice-versa for the Write bit, too.

I'm sure I'll now get 100 complaints about my lack of "Proper C Coding Skills" but it works, and that's good enough for me!! And No$GBA, too, which still insists my DS Coding is a "Technically rare masterpiece" )

-=-=-
''Load, Next List!''
Tue, 11 Dec 2007, 19:59
spinal
Seems to work fine, but the mp3 lib doesnt like starting in the middle. I'll mess with it a bit more, see if anything works.

-=-=-
Check out my excellent homepage!