Menu

READ A LINKED LIST THAT WAS SAVED IN A FILE?

Anonymous
2007-12-05
2012-09-26
  • Anonymous

    Anonymous - 2007-12-05

    How I read a linked list that was saved in a file?

    These are the global variables:

    struct mappointlabel
    { char mappoint;
    int color;
    };
    mappointlabel maplab[22][80];

    typedef struct mapslist
    { mappointlabel maplab[22][80];
    char mapname[20];
    int mapnumber;
    mapslist next;
    }maps;
    maps novoa,
    nnew, first, last, aux1, aux2, var_arcmap;
    FILE *arcmap;

    And here is the part where I save a list to a file and then try to read it:

    void allocatemap(int)
    { nnew=(maps *)malloc(sizeof(maps));
    if (nnew == NULL)
    { printf("\n Insulficient memory");
    exit(1);
    }
    if (first== NULL)
    { first=last=nnew;
    nnew->mapnumber=1;
    nnew->next= NULL;
    }
    else
    { nnew->next= NULL;
    last->next=nnew;
    last=nnew;
    nnew->mapnumber=first->mapnumber+1;
    }

    strcpy((nnew->mapname), novoa.mapname);
    for (i=0; i<22; i++)
    for (j=0; j<80; j++)
    { nnew->maplab[i][j].mappoint = maplab[i][j].mappoint;
    nnew->maplab[i][j].color= maplab[i][j].color;
    textcolor(nnew->maplab[i][j].color);
    gotoxy(j+1,i+3);
    printf("%c", nnew->maplab[i][j].mappoint);
    }
    system("cls");
    arcmap= fopen("gamemaps.gfl", "a+");
    fwrite(nnew, sizeof(mapslist),1,arcmap);
    fread(nnew, sizeof(mapslist),1,arcmap);
    i=0;
    j=0;
    while(!feof(arcmap))
    { printf("%c", nnew->maplab[i][j].mappoint);
    fread(nnew, sizeof(mapslist),1,arcmap);
    i+=1;
    j+=1;
    }
    getchar();
    }

    It don't write nothing in the screen.

    if I try this (USING '&' and changing to write the map name) it show strange characters like trash in memory:

    system("cls");
    arcmap= fopen("gamemaps.gfl", "a+");
    fwrite(nnew, sizeof(mapslist),1,arcmap);
    fread(&nnew, sizeof(mapslist),1,arcmap);
    i=0;
    j=0;
    while(!feof(arcmap))
    { printf("%s", nnew->mapname);
    fread(&nnew, sizeof(mapslist),1,arcmap);
    }
    getchar();
    }

     
    • Anonymous

      Anonymous - 2007-12-06

      I MADE IT. hahaha. :)
      The program is working now. I was not able to load my map becouse I need to recreate the nnew space in memory to load the file content into it.

      Now this part is working:

      void allocatemap(int)
      { nnew=(maps *)malloc(sizeof(maps));
      if (nnew == NULL)
      { printf("\n Insulficient memory");
      exit(1);
      }
      if (first== NULL)
      { first=last=nnew;
      nnew->mapnumber=1;
      nnew->next= NULL;
      }
      else
      { nnew->next= NULL;
      last->next=nnew;
      last=nnew;
      nnew->mapnumber=first->mapnumber+1;
      }

      strcpy((nnew->mapname), novoa.mapname);
      for (i=0; i<22; i++)
      for (j=0; j<80; j++)
      { nnew->maplab[i][j].mappoint = maplab[i][j].mappoint;
      nnew->maplab[i][j].color= maplab[i][j].color;
      textcolor(nnew->maplab[i][j].color);
      gotoxy(j+1,i+3);
      printf("%c", nnew->maplab[i][j].mappoint);
      }
      system("cls");
      arcmap= fopen("gamemaps.gfl", "a+");
      fwrite(nnew, sizeof(mapslist),1,arcmap);
      fseek(arcmap, 0,SEEK_SET);
      fread(nnew, sizeof(mapslist),1,arcmap);
      for (i=0; i<22; i++)
      for (j=0; j<80; j++)
      { gotoxy(j+1,i+3);
      textcolor(nnew->maplab[i][j].color);
      printf("%c", nnew->maplab[i][j].mappoint);
      fread(nnew, sizeof(mapslist),1,arcmap);
      }
      fclose(arcmap);
      getchar();
      }

      And this one in the begin too:

      nnew=(maps *)malloc(sizeof(maps)); <---- Alocating nnew to receive file data.
      arcmap= fopen("gamemaps.gfl", "a+");
      fseek(arcmap, 0,SEEK_SET);
      fread(nnew, sizeof(mapslist),1,arcmap);
      for (i=0; i<22; i++)
      for (j=0; j<80; j++)
      { gotoxy(j+1,i+3);
      textcolor(nnew->maplab[i][j].color);
      printf("%c", nnew->maplab[i][j].mappoint);
      fread(nnew, sizeof(mapslist),1,arcmap);
      }
      getchar();

      I hope I can save and load a large linked list now.

      Thanks for help.

       
    • Osito

      Osito - 2007-12-05

      I don't use fwrite and fread much, but I think fwrite leaves the file pointer at the end of the file, so to fread it back you'd need to rewind by the size of your structure.

       
    • Anonymous

      Anonymous - 2007-12-05

      How I do it??

       
      • Osito

        Osito - 2007-12-05

        Google rewind c++.

        You might want fseek instead, I'm not sure (google fseek c++)

        The internet. It's like magic.

         
    • Anonymous

      Anonymous - 2007-12-05

      0 Æ  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0 Æ  0 Æ  0PÆ  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0
      My file have it inside (vamosnessa is a string):

       0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  vamosnessa

       
    • Anonymous

      Anonymous - 2007-12-05

      I think I understood you. I used fseek. But when I close my program and try to load the file it crash.

       
    • Anonymous

      Anonymous - 2007-12-05

      IF I put:

      void main(int)
      {
      system("cls");
      arcmap= fopen("gamemaps.gfl", "a+");
      fseek(arcmap, 0,SEEK_SET);
      fread(first, sizeof(mapslist),1,arcmap);
      i=0;
      j=0;
      while(!feof(arcmap))
      { gotoxy(i+1,j+1);
      printf("%s", first->mapname);
      fread(first, sizeof(mapslist),1,arcmap);
      i+=1;
      j+=1;
      }
      getchar();
      }

      The program crash.

       
      • Osito

        Osito - 2007-12-05

        You should always check for NULL when opening a file (after fopen make sure arcmap isn't NULL). Trying to fread with arcmap NULL will cause a crash.

        I'm not sure what would happen if your input file doesn't have enough bytes to fill one mapslist. You should probably check the return value of fread each time as well.

         
    • Anonymous

      Anonymous - 2007-12-05

      The problem you face is well known and studied. Google about "serialize".

       
    • Anonymous

      Anonymous - 2007-12-05

      arcmap is NULL. What I do???

       
      • Osito

        Osito - 2007-12-05

        Figure out why. :) Is that filename valid? Is your program looking in the right folder for it? Does another program have the file open, thus preventing yours from opening it as A+?

         
    • Anonymous

      Anonymous - 2007-12-05

      arcmap is NULL before I open the file, then after it, its nomore NULL.

       
      • Osito

        Osito - 2007-12-05

        That's good, that's how it should be. So you have to figure out which line causes it to crash. For something like what you're doing, I often stick in getchar() in front of the line I suspect and see if it crashes before it gets to that point. I'm sure there are better ways with debuggers and such, but to each his own.

         
    • Anonymous

      Anonymous - 2007-12-05

      The bad line is the: printf("%c", first->maplab[i][j].mappoint); cause if I delet it the program work. But this is the most important line, the line that will show me what is in the file.

       
      • Osito

        Osito - 2007-12-05

        You'd have to show me more code. I remember seeing something earlier where you were incrementing i and j each time through a loop. Since maplab is 22 x 80, you might be exceeding the max with i at some point.

         
    • Anonymous

      Anonymous - 2007-12-05

      This is the entire code, its more than 1400 lines:
      I used &(check the end of the program) and it show me strange characters. It accurs also in the start, in function main.

      include <stdio.h>

      include <windows.h>

      include <stdlib.h>

      include <conio2.h>

      include <iostream>

      using namespace std;

      void resumegame(int);
      void newgame(int);
      void loadgame(int);
      void savegame(int);
      void selectprofile(int);
      void options(int);
      void help(int);
      void sdk(int);
      void quit(int);
      void mainmenu(int);
      void printmain(int);
      void asciilist(int);
      void initmapeditor(int);
      void setgamekeys(int);
      void centralize(int, char[80]);
      void intro(int);
      void buildmap(int);
      void printmap(int, int);
      void mapeditor(int);
      void savemap(int);
      void loadmap(int);
      void allocatemap(int);

      int buildmaincharacter(int);

      char maincharacter[3][3], a, b, selection, maincharacterdow[1][6], soundonoff[3];
      char key, keyup, keydown, keyright, keyleft, keyuse, keypause, currentkey, mapchar1, mapchar2;

      int i,j, numpas, charstate, direction, readyquit, selecnum, selecclear, sound, position, pos, mapnunber, mapopen, mapname;

      char map[22][80];

      struct mappointlabel
      { char mappoint;
      int color;
      };
      mappointlabel maplab[22][80];

      typedef struct mapslist
      { mappointlabel maplab[22][80];
      char mapname[20];
      int mapnumber;
      mapslist next;
      }maps;
      maps novoa,
      nnew, first, last, aux1, aux2, var_arcmap;
      FILE *arcmap;

      typedef struct game
      { int mapnunber;
      int points, level, ammo1, ammo2, ammo3, ammo4, money, health;
      } gamefile;
      gamefile var_arq;
      FILE *arq;

      /===================================== MAIN ===================================/
      main()
      { keyup='w';
      keydown='s';
      keyright='d';
      keyleft='a';
      keypause='p';
      keyuse='k';

      arcmap= fopen("gamemaps.gfl", "a+");
      fseek(arcmap, 0,SEEK_SET);
      fread(&first, sizeof(mapslist),1,arcmap);
      for (i=0; i<22; i++)
      for (j=0; j<80; j++)
      { fread(&first, sizeof(mapslist),1,arcmap);
      printf("%c", &first->maplab[i][j].mappoint);
      }
      getchar();

      selection=175;

      centralize(10, "PLEASE TURN OFF YOUR CAPS LOCK, IF ITS ON THE GAME WILL NOT WORK PROPERLY");
      centralize(14, "PRESS ANY KEY TO CONTINUE");
      getch();
      system("cls");
      centralize(8, "GAME BY:");
      centralize(13, "ANTHONY GAUDINO");
      centralize(15, "AND\n\n");
      centralize(17, "FILIPE EDIMUNDO");
      _sleep(1);
      system("cls");

      centralize(6, "DO YOU WANT TO WATCH GAME INTRO?");
      gotoxy(39, 10);
      printf("YES");
      gotoxy(39, 12);
      printf("NO");
      gotoxy(37,10);
      printf("%c", selection);
      selecnum=1;

      while (readyquit!=1)
      { key='\0';
      key=getch();

       if (key==keyup)
       { selecclear=selecnum;
         if (selecnum==1) 
            selecnum=2;
         else
         if (selecnum!=1)
            selecnum=selecnum-1;
       }
       if (key==keydown)
       { selecclear=selecnum;
         if (selecnum==2)
            selecnum=1;
         else
         if (selecnum!=2)
            selecnum=selecnum+1;
       }
      
       if (key==keyuse)
       { switch (selecnum)
         { case 1:     
           intro(1);
                break;  
           case 2:
           mainmenu(1);
                break;
         }
       }
      
       switch (selecclear)
       { case 1:
         gotoxy(37,10);
         printf(&quot; &quot;);
              break;
         case 2:
         gotoxy(37,12);
         printf(&quot; &quot;);
              break;
       }
      
       switch (selecnum)
       { case 1:
         gotoxy(37,10);
         printf(&quot;%c&quot;, selection);
              break;
         case 2:
         gotoxy(37,12);
         printf(&quot;%c&quot;, selection);
              break;
       }
      

      }

      gamefile gamef;

      mainmenu(1);
      / =====================================================/
      arq= fopen("game.gfl", "w+");
      if (!arq)
      printf ("Erro na abertura do arquivo.");

       if (fwrite(&amp;var_arq, sizeof(var_arq), 1, arq)!=1);
         printf(&quot;/n Erro de gravaçao&quot;);
      
        fread(&amp;var_arq, sizeof(var_arq), 1, arq);
      

      / =====================================================/

      }

      /================================= RESUME GAME ================================/
      void resumegame(int a)
      { for (i=0;i<23;i++)
      for (j=0;j<81;j++)
      {
      map[i][j]='o';
      gotoxy(j, i);
      printf("%c", map[i][j]);
      }

      buildmaincharacter(charstate);
      key='\0';
      while (key!='=')
      {
      key='\0';

        key=getch();
      
        if (key!=keyup &amp;&amp; key!=keydown &amp;&amp; key!=keyright &amp;&amp; key!=keyleft)
          charstate=0;
      
        if (key==keyright)
        {  charstate=1;
           numpas+=1;
        }
        if (key==keyleft)
        {  charstate=2;
           numpas-=1;
        }
        if (key==keyup)
        {  charstate=3;
        }
        if (key==keypause)
        {  mainmenu(1);
        }
        if (key==keydown)
        {  charstate=4;
        }
        buildmaincharacter(charstate);
      

      }
      }

      /============================= BUILD MAIN CHARACTER ===========================/
      int buildmaincharacter(int charstate)
      { if (charstate==0)
      { for (i=19;i<22;i++)
      for (j=0;j<3;j++)
      { gotoxy(j+numpas, i);
      printf("%c", maincharacter[i-19][j]);
      }
      }

      / =====================================================/

      if (charstate==1)
      { _sleep(200);
      for (i=19;i<22;i++)
      for (j=0;j<3;j++)
      { gotoxy(numpas-1, i);
      printmap(i, j);
      }
      maincharacter[2][0]=32;
      maincharacter[2][1]=179;
      maincharacter[2][2]=32;

       for (i=19;i&lt;22;i++)
       for (j=0;j&lt;3;j++)
       {  gotoxy(j+numpas, i);
          printf(&quot;%c&quot;, maincharacter[i-19][j]);
       }
      
       _sleep(200);
       for (i=19;i&lt;22;i++)
       for (j=0;j&lt;3;j++)
       {  gotoxy(numpas-1, i);
          printmap(i, j);
       }
       maincharacter[2][0]=32;
       maincharacter[2][1]=179;
       maincharacter[2][2]=92;
       for (i=19;i&lt;22;i++)
       for (j=0;j&lt;3;j++)
       {  gotoxy(j+numpas, i);
          printf(&quot;%c&quot;, maincharacter[i-19][j]);
       }
      

      }

      / =====================================================/

      if (charstate==2)
      { _sleep(200);
      for (i=19;i<22;i++)
      for (j=0;j<3;j++)
      { gotoxy(numpas+3, i);
      printmap(i, j);
      }
      maincharacter[2][0]=32;
      maincharacter[2][1]=179;
      maincharacter[2][2]=32;

       for (i=19;i&lt;22;i++)
       for (j=0;j&lt;3;j++)
       {  gotoxy(j+numpas, i);
          printf(&quot;%c&quot;, maincharacter[i-19][j]);
       }
      
       _sleep(200);
       for (i=19;i&lt;22;i++)
       for (j=0;j&lt;3;j++)
       {  gotoxy(numpas+3, i);
          printmap(i, j);
       }
       maincharacter[2][0]=47;
       maincharacter[2][1]=179;
       maincharacter[2][2]=32;
       for (i=19;i&lt;22;i++)
       for (j=0;j&lt;3;j++)
       {  gotoxy(j+numpas, i);
          printf(&quot;%c&quot;, maincharacter[i-19][j]);
       }
      

      }

      / =====================================================/

      if (charstate==3)
      { _sleep(200);
      for (j=0;j<3;j++)
      { gotoxy(j+numpas, 21);
      printmap(21, j);
      }

       maincharacter[2][0]=47;
       maincharacter[2][1]=32;
       maincharacter[2][2]=92;
      
       for (i=18;i&lt;21;i++)
       for (j=0;j&lt;3;j++)
       {  gotoxy(j+numpas, i);
          printf(&quot;%c&quot;, maincharacter[i-18][j]);
       }
      
       _sleep(200);
       for (i=17;i&lt;20;i++)
       for (j=0;j&lt;3;j++)
       {  gotoxy(j+numpas, i);
          printf(&quot;%c&quot;, maincharacter[i-17][j]);
       }
      
       for (j=0;j&lt;3;j++)
       {  gotoxy(j+numpas, 20);
          printmap(20, j);
       }
      

      / down/
      _sleep(200);
      for (i=18;i<21;i++)
      for (j=0;j<3;j++)
      { gotoxy(j+numpas, i);
      printf("%c", maincharacter[i-18][j]);
      }

       for (j=0;j&lt;3;j++)
       {  gotoxy(j+numpas, 17);
          printmap(17, j);
       }
      
       _sleep(200);
       maincharacter[2][0]=47;          
       maincharacter[2][1]=179;
       maincharacter[2][2]=32;
       for (i=19;i&lt;22;i++)
       for (j=0;j&lt;3;j++)
       {  gotoxy(j+numpas, i);
          printf(&quot;%c&quot;, maincharacter[i-19][j]);
       }
      
       for (j=0;j&lt;3;j++)
       {  gotoxy(j+numpas, 18);
          printmap(18, j);
       }
      

      }

      if (charstate==4)
      { _sleep(200);

       for (i=0;i&lt;3;i++)
       for (j=0;j&lt;6;j++)
       {  gotoxy(j+numpas, i+18);
          printmap(i+18,j);
       }
      
       maincharacterdow[0][0]='&gt;';
       maincharacterdow[0][1]='-';
       maincharacterdow[0][2]='&gt;';
       maincharacterdow[0][3]='(';
       maincharacterdow[0][4]=32;
       maincharacterdow[0][5]=')';
      
       for (i=21;i&lt;22;i++)
       for (j=0;j&lt;6;j++)
       {  gotoxy(j+numpas, i);
          printf(&quot;%c&quot;, maincharacterdow[i-21][j]);
       }
      
       for (i=0;i&lt;3;i++)
       for (j=0;j&lt;6;j++)
       {  gotoxy(j+numpas, i+18);
          printmap(i+18, j);
       }
      

      }
      }

      /=================================== NEW GAME =================================/
      void newgame(int a)
      { maincharacter[0][0]=40;
      maincharacter[0][1]=32;
      maincharacter[0][2]=41;

        maincharacter[1][0]=47;
        maincharacter[1][1]=179;
        maincharacter[1][2]=92;
      
       maincharacter[2][0]=32;
       maincharacter[2][1]=179;
       maincharacter[2][2]=92;
      
       for (i=0;i&lt;23;i++)
       for (j=0;j&lt;81;j++)
       { 
          map[i][j]='o';
          gotoxy(j, i);
          printf(&quot;%c&quot;, map[i][j]);
       }
      

      numpas=1;
      charstate=0;

      resumegame(1);
      }

      /================================== PRINT MAIN ================================/
      void printmain(int a)
      { system("cls");
      a=179;
      b=220;
      textcolor(15);
      printf(" \n");
      printf(" GAME NAME \n");
      printf(" _ _%c%c \n", b, b);
      printf(" +--%c_\------------------------+-%c-%c-----o%c _ \n", a, a, a, a);
      printf(" %c-==========================\======\\\\\\\\HO) \n", a);
      printf(" %c_ I N F I N I T Y \___\\\\\\\\/ \n", a);
      printf(" %c
      ___-__/\\~~-- \n", a);
      printf(" %c
      \\_\\
      \\\\\\ %c(__==%c~~~~~(-- )--~~\n", a, a, a);
      printf(" \ /~~~~\~~\ | \\_ /( \n");
      printf(" %c%c %c--%c \ () \\\ \n", a, a, a, a);
      printf(" %c\
      / / ()\ \\\ \n", a);
      printf(" `~~~~~~~~~-. \ \\ \ \n");
      printf(" \ \ (SV) \\- \n");
      printf(" \ \ \\ \n");
      printf(" \ \ \\ \n");
      printf(" \ \ \\ \n");
      printf(" \ \ () \\ \n", a, a);
      printf("
      \_\__====~~~\ \n");
      printf(" (__%c ", a);
      printf(" ");
      }

      /================================== MAIN MENU =================================/
      void mainmenu(int a)
      { printmain(1);

      key='\0';
      selecnum=1;

      gotoxy(4,6);
      printf("RESUME GAME");
      gotoxy(4,8);
      printf("NEW GAME");
      gotoxy(4,10);
      printf("LOAD GAME");
      gotoxy(4,12);
      printf("SAVE GAME");
      gotoxy(4,14);
      printf("SELECT PROFILE");
      gotoxy(4,16);
      printf("OPTIONS");
      gotoxy(4,18);
      printf("HELP");
      gotoxy(4,20);
      printf("SDK");
      gotoxy(4,22);
      printf("QUIT");

      gotoxy(2,6);
      printf("%c", selection);
      while (readyquit!=1)
      { key='\0';

        key=getch();
      
        if (key==keyup)
        { selecclear=selecnum;
          if (selecnum==1) 
            selecnum=9;
          else
          if (selecnum!=1)
            selecnum=selecnum-1;
        }
        if (key==keydown)
        { selecclear=selecnum;
          if (selecnum==9)
            selecnum=1;
          else
          if (selecnum!=9)
            selecnum=selecnum+1;
        }
        if (key==keyuse)
        { switch (selecnum)
          { case 1:     
            resumegame(1);
                 break;  
            case 2:
            newgame(1);
                 break;
            case 3:
            loadgame(1);
                 break;
            case 4:
            savegame(1);
                 break;  
            case 5:
            selectprofile(1);
                 break;
            case 6:
            options(1);
                 break;
            case 7:
            help(1);
                 break;
            case 8:
            sdk(1);
                 break; 
            case 9:
            quit(1);
                 break;
          }    
         }
      
        switch (selecclear)
        { case 1: 
          gotoxy(2,6);
          printf(&quot; &quot;);
                break;
          case 2: 
          gotoxy(2,8);
          printf(&quot; &quot;);
               break;
          case 3:
          gotoxy(2,10);
          printf(&quot; &quot;);
               break;
          case 4: 
          gotoxy(2,12);
          printf(&quot; &quot;);
                break;
          case 5:
          gotoxy(2,14);
          printf(&quot; &quot;);
                break;
          case 6:
          gotoxy(2,16);
          printf(&quot; &quot;);
                break;
          case 7:
          gotoxy(2,18);
          printf(&quot; &quot;);
                break;
          case 8:
          gotoxy(2,20);
          printf(&quot; &quot;);
                break;
          case 9:
          gotoxy(2,22);
          printf(&quot; &quot;);
                break;
        }
      
        switch (selecnum)
        { case 1: 
          gotoxy(2,6);
          printf(&quot;%c&quot;, selection);
                break;
          case 2: 
          gotoxy(2,8);
          printf(&quot;%c&quot;, selection);
               break;
          case 3:
          gotoxy(2,10);
          printf(&quot;%c&quot;, selection);
               break;
          case 4: 
          gotoxy(2,12);
          printf(&quot;%c&quot;, selection);
                break;
          case 5:
          gotoxy(2,14);
          printf(&quot;%c&quot;, selection);
                break;
          case 6:
          gotoxy(2,16);
          printf(&quot;%c&quot;, selection);
                break;
          case 7:
          gotoxy(2,18);
          printf(&quot;%c&quot;, selection);
                break;
          case 8:
          gotoxy(2,20);
          printf(&quot;%c&quot;, selection);
                break;
          case 9:
          gotoxy(2,22);
          printf(&quot;%c&quot;, selection);
                break;
        }
      

      }
      }

      /================================== LOAD GAME =================================/
      void loadgame(int a)
      {a=2;
      }

      /================================== SAVE GAME =================================/
      void savegame(int a)
      {
      }

      /================================ SELECT PROFILE ==============================/
      void selectprofile(int a)
      {
      }

      /=================================== OPTIONS ==================================/
      void options(int a)
      { printmain(1);
      if (sound=1)
      { soundonoff[0]='O';
      soundonoff[1]='F';
      soundonoff[2]='F';
      }
      else
      { soundonoff[0]='O';
      soundonoff[1]='N';
      soundonoff[2]=32;
      }
      gotoxy(1,3);
      printf(" OPTIONS ");
      sound=0;
      gotoxy(4,16);
      printf("SET GAME KEYS");
      gotoxy(4,20);
      printf("BACK");
      gotoxy(2,14);
      printf("%c", selection);
      selecnum=1;
      while (readyquit!=1)
      { key='\0';

       gotoxy(4,14);
       printf(&quot;GAME SOUNDS ON/OFF     %s  %d&quot;, &amp;soundonoff, sound);
      
       key=getch();
      
       if (key==keyup)
       { selecclear=selecnum;
         if (selecnum==1) 
            selecnum=3;
         else
         if (selecnum!=1)
            selecnum=selecnum-1;
       }
       if (key==keydown)
       { selecclear=selecnum;
         if (selecnum==3)
            selecnum=1;
         else
         if (selecnum!=3)
            selecnum=selecnum+1;
       }
      
       if (key==keyuse)
       { switch (selecnum)
         { case 1:     
           if (sound==1)
           { soundonoff[0]='O';
             soundonoff[1]='F';
             soundonoff[2]='F';
             sound=0;
           }
           else
           { soundonoff[0]='O';
             soundonoff[1]='N';
             soundonoff[2]=32;
             sound=1;
           }
                break;  
           case 2:
           setgamekeys(1);
                break;
           case 3:
           mainmenu(1);
                break;
         }
       }
      
       switch (selecclear)
       { case 1:
         gotoxy(2,14);
         printf(&quot; &quot;);
              break;
         case 2:
         gotoxy(2,16);
         printf(&quot; &quot;);
              break;
         case 3:
         gotoxy(2,20);
         printf(&quot; &quot;);
              break;
       }
      
       switch (selecnum)
       { case 1:
         gotoxy(2,14);
         printf(&quot;%c&quot;, selection);
              break;
         case 2:
         gotoxy(2,16);
         printf(&quot;%c&quot;, selection);
              break;
         case 3:
         gotoxy(2,20);
         printf(&quot;%c&quot;, selection);
              break;
       }
      

      }
      }

      /===================================== HELP ===================================/
      void help(int a)
      {
      }

      /===================================== SDK ====================================/
      void sdk(int a)
      { system("cls");
      gotoxy(1,3);
      printf(" SDK \n\n");
      printf("The SDK is your way to make some easy changes in this game, here you can access \n");
      printf("some tools, the map editor and the ASCII list. \n\n");
      printf("Just select the tool you want to use bellow:");
      gotoxy(4,14);
      printf("ASCII LIST");
      gotoxy(4,16);
      printf("MAP EDITOR");
      gotoxy(4,20);
      printf("BACK");
      gotoxy(2,14);
      printf("%c", selection);
      selecnum=1;
      while (readyquit!=1)
      { key='\0';
      key=getch();

       if (key==keyup)
       { selecclear=selecnum;
         if (selecnum==1) 
            selecnum=3;
         else
         if (selecnum!=1)
            selecnum=selecnum-1;
       }
       if (key==keydown)
       { selecclear=selecnum;
         if (selecnum==3)
            selecnum=1;
         else
         if (selecnum!=3)
            selecnum=selecnum+1;
       }
      
       if (key==keyuse)
       { switch (selecnum)
         { case 1:     
           asciilist(1);
                break;  
           case 2:
           mapeditor(1);
                break;
           case 3:
           mainmenu(1);
                break;
         }
       }
      
       switch (selecclear)
       { case 1:
         gotoxy(2,14);
         printf(&quot; &quot;);
              break;
         case 2:
         gotoxy(2,16);
         printf(&quot; &quot;);
              break;
         case 3:
         gotoxy(2,20);
         printf(&quot; &quot;);
              break;
       }
      
       switch (selecnum)
       { case 1:
         gotoxy(2,14);
         printf(&quot;%c&quot;, selection);
              break;
         case 2:
         gotoxy(2,16);
         printf(&quot;%c&quot;, selection);
              break;
         case 3:
         gotoxy(2,20);
         printf(&quot;%c&quot;, selection);
              break;
       }
      }
      

      }

      /===================================== QUIT ===================================/
      void quit(int a)
      {
      printmain(1);
      gotoxy(4,13);
      printf("DO YOU REALLY WANT TO QUIT?");
      gotoxy(4,16);
      printf("YES");
      gotoxy(4,18);
      printf("NO");
      gotoxy(2,16);
      printf("%c", selection);
      selecnum=1;

      while (readyquit!=1)
      { key='\0';
      key=getch();

       if (key==keyup)
       { selecclear=selecnum;
         if (selecnum==1) 
            selecnum=2;
         else
         if (selecnum!=1)
            selecnum=selecnum-1;
       }
       if (key==keydown)
       { selecclear=selecnum;
         if (selecnum==2)
            selecnum=1;
         else
         if (selecnum!=2)
            selecnum=selecnum+1;
       }
      
       if (key==keyuse)
       { switch (selecnum)
         { case 1:     
           exit(1);
                break;  
           case 2:
           mainmenu(1);
                break;
         }
       }
      
       switch (selecclear)
       { case 1:
         gotoxy(2,16);
         printf(&quot; &quot;);
              break;
         case 2:
         gotoxy(2,18);
         printf(&quot; &quot;);
              break;
       }
      
       switch (selecnum)
       { case 1:
         gotoxy(2,16);
         printf(&quot;%c&quot;, selection);
              break;
         case 2:
         gotoxy(2,18);
         printf(&quot;%c&quot;, selection);
              break;
       }
      }
      

      }

      /================================== ASCII LIST ================================/
      void asciilist(int)
      { system("cls");
      gotoxy(1,3);
      printf("The ASCII list will show you the 256 ASCII charactrers and its correspondent \n");
      printf("nunbers in decimal. Its very useful for manual edit this game. \n\n");
      printf("PRESS ANY KEY TO CONTINUE");
      getch();
      system("cls");
      char c, chartest[3][11];
      int i, j;
      for (i=0; i<149; i++)
      { c=i;
      printf("%c (%d) \n\n", c, i);
      }
      getch();
      for (i=148; i<257; i++)
      { c=i;
      printf("%c (%d) \n\n", c, i);
      }
      getch();
      sdk(1);
      }

      /================================= INITMAPEDITOR ==============================/
      void initmapeditor(int)
      { int x, y;
      system("cls");
      gotoxy(1,3);
      printf("The MAP EDITOR will help you edit your own maps. Use your movement keys to\n");
      printf("change positions of the map, press use key to change that position, then\n");
      printf("write the decimal value of a ASCII char press enter and write the nunber of a\n");
      printf("color for this char. Press pause button to stop working and open the menu where\n");
      printf("you can save your work. \n");
      centralize(9, "Take in mink you need to setup the first char you select twice.");
      centralize(12,"PRESS ANY KEY TO START MAP EDITOR");
      getch();
      system("cls");
      mapopen=1;
      for (i=0;i<22;i++)
      for (j=0;j<80;j++)
      { maplab[i][j].color=15;
      maplab[i][j].mappoint='0';
      textcolor(maplab[i][j].color);
      gotoxy(j+1,i+3);
      printf("%c", maplab[i][j].mappoint);
      }
      x=1;
      y=1;
      while (key!=keypause)
      { key='\0';
      gotoxy(70,1);
      printf(" ");
      gotoxy(70,1);
      printf("%d", x);
      gotoxy(75,1);
      printf(" ");
      gotoxy(75,1);
      printf("%d", y);

      key=getch();
      
      if (key==keypause)
      mapeditor(1);
      
      if (key==keyup)
      { if (x==1)
          x=22;
        else
        if (x!=1)
          x-=1;
      }
      if (key==keydown)
      { if (x==22)
          x=1;
        else
        if (x!=22)
          x+=1;
      }
      if (key==keyright)
      { if (y==80)
          y=1;
        else
        if (y!=80)
          y+=1;
      }
      if (key==keyleft)
      { if (y==1)
          y=80;
        else
        if (y!=1)
          y-=1;
      }
      
      gotoxy(70,1);
      printf(&quot;  &quot;);
      gotoxy(70,1);
      printf(&quot;%d&quot;, x);
      gotoxy(75,1);
      printf(&quot;  &quot;);
      gotoxy(75,1);
      printf(&quot;%d&quot;, y);
      
      if (key==keyuse)
      { gotoxy(1,1);
        textcolor(15);
        printf(&quot;WRITE THE NEW CHAR: &quot;);
        scanf(&quot;%c&quot;, &amp;maplab[x-1][y-1].mappoint);
        scanf(&quot;%c&quot;, &amp;maplab[x-1][y-1].mappoint);
        gotoxy(1,1);
        printf(&quot;                            &quot;);
        gotoxy(1,1);
        printf(&quot;WRITE THE NEW COLOR: &quot;);
        scanf(&quot;%d&quot;, &amp;maplab[x-1][y-1].color);
        gotoxy(1,1);
        printf(&quot;                            &quot;);      
        buildmap(0);
      }
      

      }
      }

      /================================= SET GAME KEYS ==============================/
      void setgamekeys(int)
      { system("cls");
      centralize(2, "SET KEYS");
      centralize(4, "Select the key you want to change and press the new key.");
      centralize(6, "USE ONLY NUNBERS AND LETERS.");
      gotoxy(4,24);
      printf("BACK");
      gotoxy(2,10);
      printf("%c", selection);
      selecnum=1;
      while (readyquit!=1)
      { gotoxy(4,10);
      printf("UP KEY '%c'", keyup);
      gotoxy(4,12);
      printf("DOWN KEY '%c'", keydown);
      gotoxy(4,14);
      printf("RIGHT KEY '%c'", keyright);
      gotoxy(4,16);
      printf("LEFT KEY '%c'", keyleft);
      gotoxy(4,18);
      printf("PAUSE KEY '%c'", keypause);
      gotoxy(4,20);
      printf("USE KEY '%c'", keyuse);

       key='\0';
       key=getch();
      
       if (key==keyup)
       { selecclear=selecnum;
         if (selecnum==1) 
            selecnum=7;
         else
         if (selecnum!=1)
            selecnum=selecnum-1;
       }
       if (key==keydown)
       { selecclear=selecnum;
         if (selecnum==7)
            selecnum=1;
         else
         if (selecnum!=7)
            selecnum=selecnum+1;
       }
      
       if (key==keyuse)
       { switch (selecnum)
         { case 1:
           gotoxy(25,14);
           printf(&quot;Press the new key for UP KEY:&quot;);
           currentkey=getch();
           while (currentkey==keydown or currentkey==keyright or currentkey==keyleft or currentkey==keypause or currentkey==keyuse)
           { gotoxy(25,14);
             printf(&quot;Key already in use. Press the new key for UP KEY:&quot;);
             currentkey=getch();
           }
           gotoxy(25,14);
           printf(&quot;                                                                      &quot;);
           keyup=currentkey;     
                break;
      
           case 2:
           gotoxy(25,14);
           printf(&quot;Press the new key for DOWN KEY:&quot;);
           currentkey=getch();
           while (currentkey==keyup or currentkey==keyright or currentkey==keyleft or currentkey==keypause or currentkey==keyuse)
           { gotoxy(25,14);
             printf(&quot;Key already in use. Press the new key for DOWN KEY:&quot;);
             currentkey=getch();
           }
           gotoxy(25,14);
           printf(&quot;                                                                      &quot;);
           keydown=currentkey;
                break;
      
           case 3:
           gotoxy(25,14);
           printf(&quot;Press the new key for RIGHT KEY:&quot;);
           currentkey=getch();
           while (currentkey==keyup or currentkey==keydown or currentkey==keyleft or currentkey==keypause or currentkey==keyuse)
           { gotoxy(25,14);
             printf(&quot;Key already in use. Press the new key for RIGHT KEY:&quot;);
             currentkey=getch();
           }
           gotoxy(25,14);
           printf(&quot;                                                                      &quot;);
           keyright=currentkey;
                break;
      
           case 4:
           gotoxy(25,14);
           printf(&quot;Press the new key for LEFT KEY:&quot;);
           currentkey=getch();
           while (currentkey==keyup or currentkey==keydown or currentkey==keyright or currentkey==keypause or currentkey==keyuse)
           { gotoxy(25,14);
             printf(&quot;Key already in use. Press the new key for LEFT KEY:&quot;);
             currentkey=getch();
           }
           gotoxy(25,14);
           printf(&quot;                                                                      &quot;);
           keyleft=currentkey;
                break;
      
           case 5:
           gotoxy(25,14);
           printf(&quot;Press the new key for PAUSE KEY:&quot;);
           currentkey=getch();
           while (currentkey==keyup or currentkey==keydown or currentkey==keyleft or currentkey==keyright or currentkey==keyuse)
           { gotoxy(25,14);
             printf(&quot;Key already in use. Press the new key for PAUSE KEY:&quot;);
             currentkey=getch();
           }
           gotoxy(25,14);
           printf(&quot;                                                                      &quot;);
           keypause=currentkey;
                break;
      
           case 6:
           gotoxy(25,14);
           printf(&quot;Press the new key for USE KEY:&quot;);
           currentkey=getch();
           while (currentkey==keyup or currentkey==keydown or currentkey==keyleft or currentkey==keyright or currentkey==keypause)
           { gotoxy(25,14);
             printf(&quot;Key already in use. Press the new key for USE KEY:&quot;);
             currentkey=getch();
           }
           gotoxy(25,14);
           printf(&quot;                                                                      &quot;);
           keyuse=currentkey;
                break;
      
           case 7:
           options(1);
                break;
         }
       }
      
       switch (selecclear)
       { case 1:
         gotoxy(2,10);
         printf(&quot; &quot;);
              break;
         case 2:
         gotoxy(2,12);
         printf(&quot; &quot;);
              break;
         case 3:
         gotoxy(2,14);
         printf(&quot; &quot;);
              break;
         case 4:
         gotoxy(2,16);
         printf(&quot; &quot;);
              break;
         case 5:
         gotoxy(2,18);
         printf(&quot; &quot;);
              break;
         case 6:
         gotoxy(2,20);
         printf(&quot; &quot;);
              break;
         case 7:
         gotoxy(2,24);
         printf(&quot; &quot;);
              break;
       }
      
       switch (selecnum)
       { case 1:
         gotoxy(2,10);
         printf(&quot;%c&quot;, selection);
              break;
         case 2:
         gotoxy(2,12);
         printf(&quot;%c&quot;, selection);
              break;
         case 3:
         gotoxy(2,14);
         printf(&quot;%c&quot;, selection);
              break;
         case 4:
         gotoxy(2,16);
         printf(&quot;%c&quot;, selection);
              break;
         case 5:
         gotoxy(2,18);
         printf(&quot;%c&quot;, selection);
              break;
         case 6:
         gotoxy(2,20);
         printf(&quot;%c&quot;, selection);
              break;
         case 7:
         gotoxy(2,24);
         printf(&quot;%c&quot;, selection);
              break;
       }
      }
      

      }

      /================================== CENTRALIZE ================================/
      void centralize(int pos, char frase[80])
      { position=((40-(strlen(frase))/2));
      gotoxy(position, pos);
      printf("%s", frase);
      }

      void intro(int)
      { maincharacter[0][0]=40;
      maincharacter[0][1]=32;
      maincharacter[0][2]=41;

        maincharacter[1][0]=47;
        maincharacter[1][1]=179;
        maincharacter[1][2]=92;
      
       maincharacter[2][0]=32;
       maincharacter[2][1]=179;
       maincharacter[2][2]=92;
      
       for (i=0;i&lt;23;i++)
       for (j=0;j&lt;81;j++)
       { 
          map[i][j]='o';
          gotoxy(j, i);
          printf(&quot;%c&quot;, map[i][j]);
       }
      

      for (numpas=1; numpas<20; numpas++)
      { resumegame(1);
      }
      }

      /=================================== BUILD MAP ================================/
      void buildmap(int number)
      { mapnunber=0;
      if (number==0)
      { for (i=0;i<22;i++)
      for (j=0;j<80;j++)
      { textcolor(maplab[i][j].color);
      gotoxy(j+1,i+3);
      printf("%c", maplab[i][j].mappoint);
      }
      }
      }

      /=================================== PRINT MAP ================================/
      void printmap(int y, int x)
      { textcolor(maplab[y][x].color);
      printf("%c", maplab[y][x].mappoint);
      }

      void mapeditor(int)
      { system("cls");
      gotoxy(4,14);
      printf("START NEW MAP");
      gotoxy(4,16);
      printf("SAVE MAP");
      gotoxy(4,18);
      printf("LOAD MAP");
      gotoxy(4,22);
      printf("BACK");
      gotoxy(2,14);
      printf("%c", selection);
      selecnum=1;

      while (readyquit!=1)
      { key='\0';
      key=getch();

       if (key==keyup)
       { selecclear=selecnum;
         if (selecnum==1) 
            selecnum=4;
         else
         if (selecnum!=1)
            selecnum=selecnum-1;
       }
       if (key==keydown)
       { selecclear=selecnum;
         if (selecnum==4)
            selecnum=1;
         else
         if (selecnum!=4)
            selecnum=selecnum+1;
       }
      
       if (key==keyuse)
       { switch (selecnum)
         { case 1:     
           initmapeditor(1);
                break;  
           case 2:
           savemap(1);
                break;
           case 3:
           loadmap(1);
                break;
           case 4:
           sdk(1);
                break;
         }
       }
      
       switch (selecclear)
       { case 1:
         gotoxy(2,14);
         printf(&quot; &quot;);
              break;
         case 2:
         gotoxy(2,16);
         printf(&quot; &quot;);
              break;
         case 3:
         gotoxy(2,18);
         printf(&quot; &quot;);
              break;
         case 4:
         gotoxy(2,22);
         printf(&quot; &quot;);
              break;
       }
      
       switch (selecnum)
       { case 1:
         gotoxy(2,14);
         printf(&quot;%c&quot;, selection);
              break;
         case 2:
         gotoxy(2,16);
         printf(&quot;%c&quot;, selection);
              break;
         case 3:
         gotoxy(2,18);
         printf(&quot;%c&quot;, selection);
              break;
         case 4:
         gotoxy(2,22);
         printf(&quot;%c&quot;, selection);
              break;
       }
      }
      

      }

      /=================================== LOAD MAP =================================/
      void loadmap(int)
      {
      }

      /=================================== SAVE MAP =================================/
      void savemap(int)
      { if (mapopen==0)
      { centralize(10, "THERE'S NO MAP OPEN TO SAVE");
      centralize(12, "PRESS ANY KEY TO RETURN");
      getch();
      centralize(10, " ");
      centralize(12, " ");
      }
      else
      { system("cls");
      centralize(10, "WRITE THE NAME OF YOUR MAP");
      centralize(11, "REMENBER TO USE ONLY NUNBERS AND LETERS\n\n");
      gets(novoa.mapname);
      allocatemap(1);
      system("cls");
      centralize(10, "FILE SAVED SUCESSFULLY");
      centralize(12, "PRESS ANY KEY TO CONTINUE");
      getch();
      mapeditor(1);
      }
      }

      /================================= ALLOCATE MAP ===============================/
      void allocatemap(int)
      { nnew=(maps *)malloc(sizeof(maps));
      if (nnew == NULL)
      { printf("\n Insulficient memory");
      exit(1);
      }
      if (first== NULL)
      { first=last=nnew;
      nnew->mapnumber=1;
      nnew->next= NULL;
      }
      else
      { nnew->next= NULL;
      last->next=nnew;
      last=nnew;
      nnew->mapnumber=first->mapnumber+1;
      }

      strcpy((nnew->mapname), novoa.mapname);
      for (i=0; i<22; i++)
      for (j=0; j<80; j++)
      { nnew->maplab[i][j].mappoint = maplab[i][j].mappoint;
      nnew->maplab[i][j].color= maplab[i][j].color;
      textcolor(nnew->maplab[i][j].color);
      gotoxy(j+1,i+3);
      printf("%c", nnew->maplab[i][j].mappoint);
      }
      system("cls");
      arcmap= fopen("gamemaps.gfl", "a+");
      fwrite(&nnew, sizeof(mapslist),1,arcmap);
      fseek(arcmap, 0,SEEK_SET);
      fread(&nnew, sizeof(mapslist),1,arcmap);
      for (i=0; i<22; i++)
      for (j=0; j<80; j++)
      {
      printf("%c", &nnew->maplab[i][j].mappoint);
      } fread(&nnew, sizeof(mapslist),1,arcmap);
      fclose(arcmap);
      getchar();
      }

       
      • Osito

        Osito - 2007-12-06

        In this part:

        for (i=0; i<22; i++)
        for (j=0; j<80; j++)
        { fread(&first, sizeof(mapslist),1,arcmap);
        printf("%c", &first->maplab[i][j].mappoint)
        ;
        }

        I don't understand why you're doing fread each time through the loop. It seems like you're reading a whole mapslist each time but then printing one point.

         
    • Anonymous

      Anonymous - 2007-12-06

      If I put this fread the program show me a more near to the map I crated if I don't put it there, but both, if I pu or not it don't show the map corectly.

       
    • Anonymous

      Anonymous - 2007-12-06

      And if I remove all the & in the end of file, the program only show me ´ ´. But it must show my map that is a lot of zeros.

       

Log in to post a comment.

Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.