forums.ps2dev.org Forum Index forums.ps2dev.org
Homebrew PS2, PSP & PS3 Development Discussions
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Int and float from file to array, been stumped for 5 hours

 
Post new topic   Reply to topic    forums.ps2dev.org Forum Index -> PSP Development
View previous topic :: View next topic  
Author Message
Crux



Joined: 25 May 2008
Posts: 10

PostPosted: Mon Jun 02, 2008 4:37 pm    Post subject: Int and float from file to array, been stumped for 5 hours Reply with quote

Quote:
while (fgets(tempTime,11,songPort)!=NULL) {

if (fgets(tempButton,4,songPort)!=NULL) {

noteTime[arrayCounter]=atof(tempTime);
noteButton[arrayCounter]=atoi(tempButton);

}

printf("noteTime: %.1f\n", noteTime[arrayCounter]);
printf("noteButton: %i\n", noteButton[arrayCounter]);

arrayCounter++;

}


It reads from a file that looks like this:

Quote:
.1
2
.3
4
.5
6
0.7
8
0.9
10


and the output is this:
Quote:
0.000
2
0.000
4
0.000
6
0.000
8
.9
10


Notice the final float, it shows up? WTH?

Can anybody explain to me why nearly half the values return 0 (zero)? Thanks I've been messing with it for at least 5 hours with no luck.[/quote]
Back to top
View user's profile Send private message
jimparis



Joined: 10 Jun 2005
Posts: 1179
Location: Boston

PostPosted: Thu Jun 05, 2008 6:24 pm    Post subject: Reply with quote

There doesn't appear to be anything wrong in the code you showed, so it's probably memory corruption or some similar problem (arrays too small, etc). Test your code out on a PC; if you have a specific (complete) piece of code that works fine on a PC but doesn't work on the PSP then maybe someone here can point out a problem.
Back to top
View user's profile Send private message
BenHur



Joined: 20 Oct 2007
Posts: 30

PostPosted: Fri Jun 06, 2008 7:49 am    Post subject: Reply with quote

@Crux
Shouldn't your output contain the words "noteTime:" and "noteButton:"? Did it really print 3 digits after the decimal point (0.000), even though you specified 1 digit?

Anyway, if atof conversion fails it returns 0.0. Thus I would check the input strings and make sure there are no funny/unexpected chars.
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    forums.ps2dev.org Forum Index -> PSP Development All times are GMT + 10 Hours
Page 1 of 1

 
Jump to:  
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 vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group