PSP Crashes When Accessing File

Discuss the development of new homebrew software, tools and libraries.

Moderators: cheriff, TyRaNiD

Post Reply
Fabre
Posts: 18
Joined: Sun May 22, 2005 7:29 am

PSP Crashes When Accessing File

Post by Fabre »

I tried writing an app to access a file from the MS, but when I run the file, the PSP displays a black screen then turns off 10-20 seconds later.

Here is the code:

Code: Select all

#include <pspdebug.h>
#include <pspiofilemgr.h>

PSP_MODULE_INFO&#40;"FileIOTest", 0, 1, 1&#41;;

int main&#40;&#41;
&#123;
   SceUID FileID;
   char *TestFile;

   pspDebugScreenInit&#40;&#41;;

   pspDebugScreenPrintData&#40;"File Access Test",16&#41;;

   FileID = sceIoOpen&#40;"ms0&#58;/test.txt",PSP_O_RDONLY,0&#41;;

   pspDebugScreenSetXY&#40;0,1&#41;;

   if &#40;FileID == 0&#41; 
   &#123;
      pspDebugScreenPrintData&#40;"Error Opening File",18&#41;;
   &#125;
   else
   &#123;
      pspDebugScreenPrintData&#40;"File Opened",11&#41;;

      sceIoRead&#40;FileID,TestFile,10&#41;;

      pspDebugScreenSetXY&#40;0,2&#41;;
      pspDebugScreenPrintData&#40;"File Accessed",13&#41;;

      pspDebugScreenSetXY&#40;0,3&#41;;
      pspDebugScreenPrintData&#40;TestFile,10&#41;;
   &#125;

   while &#40;1&#41; &#123;&#125;

   return 0;
&#125;
Where have I gone wrong?
matkeupon
Posts: 26
Joined: Sat Jul 02, 2005 10:58 pm

Post by matkeupon »

Code: Select all

char *TestFile;
This is a pointer to an array of char, but where is the actual array ?? In your example, it is not declared, so when you're writing into this array you're writing at a random place...

Replace it with this:

Code: Select all

char TestFile&#91;11&#93;
That way, the compiler makes some room for the actual chars.
Fabre
Posts: 18
Joined: Sun May 22, 2005 7:29 am

Post by Fabre »

Thanks, I'm not too experienced with C.
Post Reply