home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
rtsi.com
/
2014.01.www.rtsi.com.tar
/
www.rtsi.com
/
OS9
/
OSK
/
GAMES
/
colossal.lzh
/
save.c
< prev
next >
Wrap
Text File
|
1991-06-06
|
2KB
|
100 lines
/* program SAVE.C - save/restore functions for ADVENT.C *\
\* WARNING: "advent.c" allocates GLOBAL storage space by *\
\* including "advdef.h". *\
\* All other modules use "advdec.h" */
#include <stdio.h>
#include <strings.h>
#include <modes.h>
#include "advent.h" /* #define preprocessor equates */
#include "advdec.h"
#define strchr index
extern char *strchr();
/*
save adventure game
*/
saveadv()
{
char *sptr;
int savefd;
char username[13];
int* base;
int* top;
int diff;
printf("What do you want to name the saved game? ");
scanf("%s", username);
if (sptr = strchr(username, '.'))
*sptr = '\0'; /* kill extension */
if (strlen(username) > 8)
username[8] = '\0'; /* max 8 char filename */
strcat(username, ".adv");
savefd = creat(username, S_IWRITE);
if (savefd == -1) {
printf("Sorry, I can't create the file...%s\n", \
username);
exit(0);
}
base = &turns;
top = &lastglob;
diff = (top - base) * sizeof(int);
if (write(savefd,(char*)base,diff) != diff) {
printf("Write error on save file...%s\n", \
username);
exit(0);
}
if (close(savefd) == -1) {
printf("Sorry, I can't close the file...%s\n", \
username);
exit(0);
}
printf("OK -- \"C\" you later...\n");
}
/*
restore saved game handler
*/
restore()
{
char username[13];
int restfd;
int c;
char *sptr;
int* base;
int* top;
int diff;
printf("What is the name of the saved game? ");
scanf("%s", username);
if (sptr = strchr(username, '.'))
*sptr = '\0'; /* kill extension */
if (strlen(username) > 8)
username[8] = '\0'; /* max 8 char filename */
strcat(username, ".adv");
restfd = open(username, S_IREAD);
if (restfd == -1) {
printf("Sorry, I can't open the file...%s\n", \
username);
exit(0);
}
base = &turns;
top = &lastglob;
diff = (top - base) * sizeof(int);
if (read(restfd,(char*)base,diff) != diff) {
printf("Read error on save file...%s\n", \
username);
exit(0);
}
if (close(restfd) == -1) {
printf("Warning -- can't close save file...%s\n", \
username);
}
}