file io with an array
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?
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!
It is a 100 int array
Code: Select all
/********************************/
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;
}