 |
forums.ps2dev.org Homebrew PS2, PSP & PS3 Development Discussions
|
| View previous topic :: View next topic |
| Author |
Message |
Ghoti
Joined: 31 Dec 2005 Posts: 288
|
Posted: Sun Jun 11, 2006 9:32 pm Post subject: Wrong with my read code? |
|
|
Hi folks,
i have this read code that reads the settings for info and saves that into variables
the problem however is that the opening of a file goes correctly but the actual reading not:
| Code: | // -----------------------------------------
//
// LoadSettings
//
// -----------------------------------------
int LoadSettings(void){
int fdout;
int fd2;
//char sTmpLetter[2];
fdout = sceIoOpen("settings.txt", PSP_O_RDONLY, 0777);
if(fdout < 0)
{
DebugPrint(1,1, "error opening SETTINGS.TXT :(");
fdout = sceIoOpen("SETTINGS.TXT", PSP_O_RDONLY, 0777);
if(fdout < 0)
{
DebugPrint(1,2, "error opening settings.txt :(");
}
}
fd2 = sceIoRead(fdout, Settings, strlen(Settings));
sprintf(sBuffer, "%i", fd2);
if(fd2 <= 0)
{
DebugPrint(1,3, "error bytes read error");
DebugPrint(1,4, sBuffer);
sceIoClose(fdout);
sceGuTerm();
sceKernelExitGame();
}
int a, i;
int aLast, aTmp;
aLast = 0;
aTmp = 1;
for (a=0;a<101;a++){
if (Settings[a] == '*'){
if (aTmp == 1) {
sprintf(sBuffer, "0");
for (i=aLast;i<a;i++){
sprintf(sBuffer, "%s%c",sBuffer,Settings[i]);
}
iLeftRightSpeed = atoi(sBuffer);
iLRSpeed = 5 + (iLeftRightSpeed *5);
aLast = a+1;
aTmp += 1;
}
else if (aTmp == 2) {
sprintf(sBuffer, "0");
for (i=aLast;i<a;i++){
sprintf(sBuffer, "%s%c",sBuffer,Settings[i]);
}
iStatusSound = atoi(sBuffer);
aLast = a+1;
aTmp += 1;
}
}
}
return 0;
}
|
fdout has value 7
fd2 has value 0
why is this? _________________ My PSP games:
Boxy II: http://www.ghoti.nl/boxyii.php
Elementals: http://www.ghoti.nl/Elementals.php |
|
| Back to top |
|
 |
moonlight
Joined: 26 Oct 2005 Posts: 567
|
Posted: Sun Jun 11, 2006 9:40 pm Post subject: |
|
|
Settings strlen(Settings)?
Maybe if you have something like this
char Settings[64];
you should do
fd2 = sceIoRead(fdout, Settings, 64-1);
if (fd2 >= 0)
Settings[fd2] = 0; |
|
| Back to top |
|
 |
Ghoti
Joined: 31 Dec 2005 Posts: 288
|
|
| Back to top |
|
 |
subbie
Joined: 05 May 2005 Posts: 122
|
Posted: Mon Jun 12, 2006 2:38 am Post subject: |
|
|
fyi, (few pointers)
strlen tells you the length of the string in the varible. So even if your array is say 64 bytes but all it contains is "" the result will be zero.
It's best to just keep track of the size of your array you're storing. Or better yet, get the length of the file using the seek command. |
|
| Back to top |
|
 |
|
|
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
|