Commit 11460f8a by gerann

Add loader.c

parent 47aa791c
Showing with 36 additions and 0 deletions
#include "Header.h"
int SaveGame(char *file, Player *p, int enemiesDefeated)
{
FILE *fh;
fh = fopen(file, "w");
if (fh == NULL)
{
fprintf(stderr, "Error opening save file!\n");
return 1;
}
fprintf(fh, "%d %d %d\n%d", p->health, p->attack, p->potionCount,
enemiesDefeated);
fclose(fh);
return 0;
}
void LoadGame(char *file, Player *p, int *enemies)
{
FILE *fh;
fh = fopen(file, "r");
if (fh == NULL)
{
fprintf(stderr, "Failed to open file %s\n", file);
exit(1);
}
fscanf(fh, "%d %d %d", &p->health, &p->attack, &p->potionCount);
fscanf(fh, "%d", enemies);
fclose(fh);
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment