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 

Wrong with my read code?

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



Joined: 31 Dec 2005
Posts: 288

PostPosted: Sun Jun 11, 2006 9:32 pm    Post subject: Wrong with my read code? Reply with quote

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
View user's profile Send private message
moonlight



Joined: 26 Oct 2005
Posts: 567

PostPosted: Sun Jun 11, 2006 9:40 pm    Post subject: Reply with quote

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
View user's profile Send private message
Ghoti



Joined: 31 Dec 2005
Posts: 288

PostPosted: Sun Jun 11, 2006 10:02 pm    Post subject: Reply with quote

Thanks it works :)
_________________
My PSP games:

Boxy II: http://www.ghoti.nl/boxyii.php
Elementals: http://www.ghoti.nl/Elementals.php
Back to top
View user's profile Send private message
subbie



Joined: 05 May 2005
Posts: 122

PostPosted: Mon Jun 12, 2006 2:38 am    Post subject: Reply with quote

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
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