/* read the puzzle from a file */
Puzzle load_puzzle (const char* file)
{
+ Puzzle p;
/* First open the GZip file */
gzFile insourcefile = gzopen (file, "rb");
if (insourcefile == NULL)
{
fprintf (stderr, "%s %s\n", ERROR_READING_FILE, COMPRESSED);
- exit (1);
+ /* return an invalid puzzle */
+ init_puzzle (&p, 0);
+ return p;
}
/* Open a temporary file to uncompress the contents */
FILE *infile = tmpfile ();
if (infile == NULL)
{
fprintf (stderr, "%s\n", ERROR_READING_FILE);
- exit (1);
+ init_puzzle (&p, 0);
+ return p;
}
/* Put the uncompressed content to the temp file */
char buf[128];
fprintf (stderr, "%s\n", ERROR_READING_FILE);
fclose (infile);
gzclose (insourcefile);
- exit (1);
+ /* return an invalid puzzle */
+ init_puzzle (&p, 0);
+ return p;
}
num = gzread (insourcefile, buf, 128);
}
fseek (infile, 0, 0);
/* Read the temporary file contents to the structure Puzzle */
- Puzzle p;
char line[MAX_CLUE_LENGTH+10];
fgets (line, MAX_CLUE_LENGTH + 10, infile);
p.grid_size = atoi (line);
puzzle object */
if (p.grid_size == 0)
{
+ fprintf (stderr, "%s\n", INVALID_PUZZLE);
init_puzzle (&p, 0);
return p;
}