| View previous topic :: View next topic |
| Author |
Message |
Crux
Joined: 25 May 2008 Posts: 10
|
Posted: Mon Jun 02, 2008 4:37 pm Post subject: Int and float from file to array, been stumped for 5 hours |
|
|
| 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 |
|
 |
jimparis
Joined: 10 Jun 2005 Posts: 1179 Location: Boston
|
Posted: Thu Jun 05, 2008 6:24 pm Post subject: |
|
|
| 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 |
|
 |
BenHur
Joined: 20 Oct 2007 Posts: 30
|
Posted: Fri Jun 06, 2008 7:49 am Post subject: |
|
|
@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 |
|
 |
|