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 

Problem with file input

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



Joined: 09 Aug 2005
Posts: 2

PostPosted: Tue Aug 09, 2005 8:11 am    Post subject: Problem with file input Reply with quote

When I read from a file, and use pgPrint (from nem's hello world sample) to display the string, the string is displayed, but the rest of the screen is filled with checkerboard pattern boxes. The same char array displays fine when it is hard-coded into the program. I then used strlen to check the length of it and, for some reason, the string has a length of 777 instead of 5. How is this even possible, with the char array being defined with an upper bound of 256? What am I doing wrong?

Code:
int main() {
/* SIZE is defined to be 256 earlier in the program. Changing this value
does not correct the problem */
    char teststr[SIZE];
    char teststr2[SIZE];
    int fd;
    int i;

//The file opened contains a 5-character string.
//I have also tried sceIoRead(fd, teststr, 5 * sizeof(char)); but it still did not work.
    fd = sceIoOpen("ms0:/PSP/GAME/TEST/config", PSP_O_RDONLY, 0777);
    sceIoRead(fd, teststr, 5);
    sceIoClose(fd);
    pgFillvram(0);

//Check and print length of string (for troubleshooting purposes)
    i = strlen(teststr);
    sprintf(teststr2, "%i", i);
    pgPrint(0,29,0x7FFF,teststr2);

/*Print out string that was read in from file.  This should just print the string, but it also fills the remainder of the screen with checkerboard-style characters (probably NULL characters, but I'm not sure) */
    pgPrint(0,30,0x7FFF,teststr);

//Unrelated code here
}
Back to top
View user's profile Send private message
Snatcher



Joined: 19 Jul 2005
Posts: 9

PostPosted: Tue Aug 09, 2005 8:30 am    Post subject: Reply with quote

You need to end each string with a NULL character, setting teststr[5] = '\0', since you are reading "raw" into the text array (and never initializing it, which is ok if you always validate)
Back to top
View user's profile Send private message
darkshadow88



Joined: 09 Aug 2005
Posts: 2

PostPosted: Tue Aug 09, 2005 8:39 am    Post subject: Reply with quote

Wow...that was awfully dumb of me *slams head on desk*

I guess that's what 14 hours of continuous programming does to you.

Thanks for your help :-)
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