Saving and Loading Problem January 27, 2009 08:08PM | Admin Registered: 16 years ago Posts: 5,132 |
FILE *pattern; void SavePattern(){ pattern = fopen("fat:/apps/Wiibreaker/data/pattern1.pattern","rb"); for(int i = 0; i < 30; i++){ putc(brickx, pattern); putc(bricky, pattern); } fclose(pattern); } void LoadPattern(){ pattern = fopen("fat:/apps/Wiibreaker/data/pattern1.pattern","rb"); for(int i = 0; i < 30; i++){ brickx = getc(pattern); bricky = getc(pattern); } fclose(pattern); }
Re: Saving and Loading Problem January 27, 2009 08:23PM | Registered: 16 years ago Posts: 441 |
Re: Saving and Loading Problem January 27, 2009 08:28PM | Registered: 16 years ago Posts: 441 |
Re: Saving and Loading Problem January 27, 2009 08:56PM | Admin Registered: 16 years ago Posts: 5,132 |
Re: Saving and Loading Problem January 27, 2009 08:59PM | Registered: 16 years ago Posts: 441 |
Re: Saving and Loading Problem January 28, 2009 01:25AM | Admin Registered: 16 years ago Posts: 5,132 |
FILE *pattern; void SavePattern(){ pattern = fopen("sd:/apps/Wiibreaker/data/pattern1.pattern","wb"); for(int i = 0; i < 30; i++){ fputc(brickx, pattern); fputc(bricky, pattern); } fclose(pattern); } void LoadPattern(){ pattern = fopen("sd:/apps/Wiibreaker/data/pattern1.pattern","rb"); for(int i = 0; i < 30; i++){ brickx = fgetc(pattern); bricky = fgetc(pattern); } fclose(pattern); }Unfortuanately, the loaded values are different that what they were when they were saved. Not that much different, but for what I'm making its kind of a problem.
Re: Saving and Loading Problem January 28, 2009 09:10AM | Registered: 15 years ago Posts: 703 |
Re: Saving and Loading Problem January 28, 2009 02:03PM | Admin Registered: 16 years ago Posts: 5,132 |
Re: Saving and Loading Problem January 28, 2009 02:29PM | Admin Registered: 16 years ago Posts: 5,132 |
Re: Saving and Loading Problem January 28, 2009 02:50PM | Registered: 15 years ago Posts: 25 |
Re: Saving and Loading Problem January 28, 2009 02:54PM | Admin Registered: 16 years ago Posts: 5,132 |
Re: Saving and Loading Problem January 28, 2009 02:54PM | Registered: 15 years ago Posts: 5 |
Re: Saving and Loading Problem January 28, 2009 03:03PM | Registered: 15 years ago Posts: 25 |
Re: Saving and Loading Problem January 28, 2009 03:19PM | Registered: 16 years ago Posts: 42 |
Re: Saving and Loading Problem January 28, 2009 03:24PM | Registered: 15 years ago Posts: 5 |
Re: Saving and Loading Problem January 28, 2009 03:55PM | Admin Registered: 16 years ago Posts: 5,132 |
Re: Saving and Loading Problem January 28, 2009 04:22PM | Registered: 15 years ago Posts: 25 |
Re: Saving and Loading Problem January 28, 2009 08:57PM | Admin Registered: 16 years ago Posts: 5,132 |
void SavePattern(){ pattern = fopen("sd:/apps/Wiibreaker/data/pattern1.pattern","wb"); for(int i = 0; i < 30; i++){ fwrite(brickx, 1, sizeof(brickx), pattern); fwrite(bricky, 1, sizeof(bricky), pattern); } fclose(pattern); } void LoadPattern(){ long LSize; char * buffer; pattern = fopen("sd:/apps/Wiibreaker/data/pattern1.pattern","rb"); // obtain file size: fseek (pattern , 0 , SEEK_END); LSize = ftell (pattern); rewind (pattern); buffer = (char*) malloc (sizeof(char)*LSize); for(int i = 0; i < 30; i++){ brickx = fread(buffer, 1, LSize, pattern); bricky = fread(buffer, 1, LSize, pattern); } fclose(pattern); free(buffer); }
Re: Saving and Loading Problem January 28, 2009 09:24PM | Registered: 16 years ago Posts: 441 |
Re: Saving and Loading Problem January 29, 2009 10:48AM | Registered: 15 years ago Posts: 25 |
fwrite(brickx, sizeof(int), 30, pattern);
fwrite(&brickx, sizeof(int), 1, pattern);will write one element of the array brickx to the file. You'll want to use the for loop in this case.
... int brickx[30]; size_t elementsRead = fread(brickx, sizeof(int), 30, pattern); ...
... int brickx[30]; int bricky[30]; for (int i = 0; i < 30; i++){ //read one element at a time fread(&brickx, sizeof(int), 1, pattern); fread(&bricky, sizeof(int), 1, pattern); .... } ...