 |
forums.ps2dev.org Homebrew PS2, PSP & PS3 Development Discussions
|
| View previous topic :: View next topic |
| Author |
Message |
RCON
Joined: 03 Aug 2005 Posts: 16
|
Posted: Tue Aug 09, 2005 5:33 am Post subject: file io with an array |
|
|
| Does anyone have a piece of code that can write to a file on the memory stick from an array and them read it back into an array? |
|
| Back to top |
|
 |
Agoln

Joined: 08 Jun 2005 Posts: 326 Location: Fort Wayne, IN
|
Posted: Tue Aug 09, 2005 6:52 am Post subject: |
|
|
I had a problem with trying to do this before, for some reason when I tried to save my entire static array, it would save fine, but when I went to load it, it didn't load it correctly. I'm not sure if it has to do with endianness. What I ended up doing is just save and read them one at a time thru an array _________________ Lego of my Ago! |
|
| Back to top |
|
 |
Snatcher
Joined: 19 Jul 2005 Posts: 9
|
Posted: Tue Aug 09, 2005 9:46 am Post subject: |
|
|
It is a 100 int array
| Code: | /********************************/
int load_keys(int file)
{
char path_ini[MAXPATH], KeyFile [] = { 'K', 'E', 'Y', '0', 0 };
int fd;
mh_strncpy( ini_data.path, now_path, MAXPATH);
KeyFile[3] += file;
_strcpy( path_ini, path_main);
_strcat( path_ini, KeyFile);
fd = sceIoOpen(path_ini,O_RDONLY, 0777);
if(fd>=0){
sceIoRead(fd, &ini_data.key, sizeof(int)*100);
sceIoClose(fd);
return 1;
}
return 0;
}
int save_keys(int file)
{
int fd;
char path_ini[MAXPATH], KeyFile [] = { 'K', 'E', 'Y', '0', 0 };
mh_strncpy( ini_data.path, now_path, MAXPATH);
KeyFile[3] += file;
_strcpy( path_ini, path_main);
_strcat( path_ini, KeyFile);
fd = sceIoOpen(path_ini,O_RDONLY, 0777);
if(fd>=0){
sceIoClose(fd);
unsigned long key;
char msg[] = { "Overwrite Key Profile 1? : OK ~: CANCEL" };
msg[22] += file;
do
{
pgFillvram(0);
text_print(100,100, msg,rgb2col(250,80,80),0,0);
pgScreenFlipV();
key = Read_Key();
if(CTRL_CROSS & key)
return 2;
pgWaitV();
}
while(!(key & CTRL_CIRCLE));
}
fd = sceIoOpen( path_ini, O_CREAT|O_WRONLY|O_TRUNC, 0777);
if(fd>=0){
sceIoWrite(fd, &ini_data.key, sizeof(int)*100);
sceIoClose(fd);
return 1;
}
return 0;
} |
|
|
| Back to top |
|
 |
rinco
Joined: 21 Jan 2005 Posts: 255 Location: Canberra, Australia
|
Posted: Tue Aug 09, 2005 6:11 pm Post subject: |
|
|
i guess you need to lose some &'s, but without data structures it's difficult to be sure.
... and your data manipulation techniques are scary. |
|
| Back to top |
|
 |
|
|
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
|