![]() |
| Forums | Gaming News | Videos | Downloads | Today's Posts | Mark Forums Read | Chat | FAQ | Members List | Contact |
| ||||||
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 ...
![]() |
|
|
LinkBack | Thread Tools |
|
|
#1 |
![]() |
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
}
|
|
|
|
|
|
#2 |
![]() PREMIUM Member
|
//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)); |
|
|
|
|
|
#3 | |
![]() |
Quote:
![]() 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 :-) |
|
|
|
|
![]() |
| Tags |
| array , char , file , problem , reading |
| Thread Tools | |
|
|