home *** CD-ROM | disk | FTP | other *** search
/ The C Users' Group Library 1994 August / wc-cdrom-cusersgrouplibrary-1994-08.iso / vol_100 / 159_01 / saveadv.c < prev    next >
C/C++ Source or Header  |  1990-05-04  |  1KB  |  56 lines

  1.  
  2.  /* SAVEADV.C  no mods for V 1.43 
  3.   *
  4.   * Modified calls of fcreat() to call fopen() with a mode setting of write.
  5.   * Modified close() call to use fclose() and removed call to fflush().
  6.   * Cahnged "savefd" from and int to pointer to FILE. -- Eco-C88 V2.72 -- BW
  7.   */
  8.  
  9. #include "advent.h"
  10.  
  11. VOID PASCAL saveadv(VOID)
  12. {
  13.     auto     char    *sptr;
  14.     auto     FILE    *savefd;
  15.     auto     char     username[14];
  16.  
  17.     printf("What do you want to call the saved game? ");
  18.     scanf("%8s", username);
  19.     for (sptr = username; *sptr; sptr++)
  20.     {
  21.     *sptr = (char) toupper(*sptr);
  22.     if (!isprint(*sptr))
  23.     {
  24.         *sptr = '\0';
  25.         break;
  26.     }
  27.     }
  28.  
  29.     if (strlen(username) == 0)
  30.     strcpy(username, "SAVE");
  31.     strcat(username, ".ADV");
  32.     printf("\nOpening save file \"%s\".\n", username);
  33.     if ((savefd = fopen(username, WRITE_BIN)) == 0)
  34.     {
  35.     printf("Sorry, I can't open the file...\n");
  36.     return;
  37.     }
  38.  
  39.     for (sptr = (char *) &turns; sptr < (char *) &lastglob; sptr++)
  40.     {
  41.     if (putc(*sptr, savefd) == -1)
  42.     {
  43.         printf("write error on save file...\n");
  44.         return;
  45.     }
  46.     }
  47.  
  48.     if (fclose(savefd) == -1)
  49.     {
  50.     printf("can't close save file...\n");
  51.     return;
  52.     }
  53.     printf("Game saved.\n\n");
  54.     return;
  55. }
  56.