QJ.NET | Videos | Forums | iPhone | MMORPG | Nintendo DS | Wii | PlayStation 3 | PSP | Xbox 360 | PC | Downloads | Contact Us
Forums | Gaming News | Videos | Downloads | Today's Posts | Mark Forums Read | Chat | FAQ | Members List | Contact

QJ.net Game Discussion - PSP, Xbox, Wii, PS3, PSP Homebrew, and PSP Guides

Go Back   QJ.net Game Discussion - PSP, Xbox, Wii, PS3, PSP Homebrew, and PSP Guides > Developers Corner > PSP Development, Hacks, and Homebrew > PSP Development Forum
The above video goes away if you are a member and logged in, so log in now!

Problem reading char array from file

This is a discussion on Problem reading char array from file within the PSP Development Forum forums, part of the PSP Development, Hacks, and Homebrew category; When I read a char array from a file, and use pgPrint to display it, the string is displayed, but ...

Reply
 
LinkBack Thread Tools
Old 08-08-2005, 12:52 PM   #1
 
Join Date: Jul 2005
Location: Michigan
Posts: 104
Trader Feedback: 0
Default Problem reading char array from file

When I read a char array from a file, and use pgPrint to display it, the string is displayed, but the rest of the screen is filled with checkerboard pattern boxes. The same char array, not read from the file, displays fine. I then used strlen to check the length of it and, for some reason, the string has a length of 777 instead of 5. 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.
    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 prints the string, followed 
by a series of characters that appear as checkerboard boxes on the screen 
(probably NULL characters, but I'm not sure) */ 
    pgPrint(0,30,0x7FFF,teststr);

//Unrelated code here
}
darkshadow88 is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Old 08-08-2005, 12:55 PM   #2
PREMIUM Member
 
PorpoiseOfEmail's Avatar
 
Join Date: Aug 2005
Posts: 35
Trader Feedback: 0
Default

//The file opened contains a 5-character string.
fd = sceIoOpen("ms0:/PSP/GAME/TEST/config", PSP_O_RDONLY, 0777);
sceIoRead(fd, teststr, 5);
sceIoClose(fd);
pgFillvram(0);

sceIoRead(fd, teststr, 5 * sizeof(char));
PorpoiseOfEmail is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Old 08-08-2005, 01:02 PM   #3
 
Join Date: Jul 2005
Location: Michigan
Posts: 104
Trader Feedback: 0
Default

Quote:
Originally Posted by PorpoiseOfEmail
sceIoRead(fd, teststr, 5 * sizeof(char));
I tried that, but I'm still having the same problem

EDIT: I fixed the problem by terminating the string with a null character. Now I'm going to go sit in a corner and reflect on how I wasted 2 or 3 hours on such a stupid mistake :-)
darkshadow88 is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Reply

Tags
array , char , file , problem , reading

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off



All times are GMT -8. The time now is 03:28 AM.



Use of this Web site constitutes acceptance of the TERMS & CONDITIONS and PRIVACY POLICY
Copyright © 2009, QJ.NET. All Rights Reserved.
Contact Us