file io with an array

Discuss the development of new homebrew software, tools and libraries.

Moderators: cheriff, TyRaNiD

Post Reply
RCON
Posts: 16
Joined: Wed Aug 03, 2005 1:02 am
Contact:

file io with an array

Post by RCON »

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?
User avatar
Agoln
Posts: 326
Joined: Wed Jun 08, 2005 3:14 am
Location: Fort Wayne, IN

Post by Agoln »

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!
Snatcher
Posts: 9
Joined: Tue Jul 19, 2005 2:31 am

Post by Snatcher »

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;
}
rinco
Posts: 255
Joined: Fri Jan 21, 2005 2:12 pm
Location: Canberra, Australia

Post by rinco »

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.
Post Reply