title: Snake game in c
body: <p>i have a snake game project but now i need to find a way to make the tail follow the head, and i already make the head first,but i still confuse on how to make the tail follow the head, i know that i have to make the tail follow the previous coordinate of the head, but i can't find a way to do it</p>
  
  <p>here's my code</p>
  
  <pre><code>#include &lt;stdio.h&gt;
  #include &lt;stdlib.h&gt;
  #include &lt;conio.h&gt;
  
  int side;
  char map[20][20];
  int z=5,c=5; //the starting position of the head
  int p=0;
  void snake(char map[20][20],int ,int )
  {
      if(p==0)
      {
          p++;
      for(int x=0;x&lt;side;x++)
          {
              map[z][c]='X';
  
             printf("%s\n",map[x]);
          }
      }
      int hc,hb,t,r,j,u,i;
      hc=getch();
      hb=getch();
      if(hb==72)//up
      {
          z--;
  
      }
      else if(hb==77)//right
      {
          c++;
  
      }
      else if(hb==80)//down
      {   
          z++;
      }
      else if(hb==75)//left
      {
          c--;
  
      }
      map[z][c]='X';
  
  
      system("CLS");  
  }
  
  void square(){
          int x,y;
  
          for(x=0;x&lt;side;x++){
                  for(y=0;y&lt;side;y++){
  
                          if(x==0||x==side-1||y==0||y==side-1){
                                  map[x][y]='X';
                          }
  
                          else{
                                  map[x][y]=' ';
                          }
                  }
          }
          snake(map,x,y);
  } 
  
  void print(){
          for(int x=0;x&lt;side;x++){
                  printf("%s\n",map[x]);
          }
  }
  
  int main()
  {
  
      printf("Input the large = ");
      scanf("%d",&amp;side); 
      fflush(stdin);
      system("CLS");
      while(true)
      {
      square();
      print();
      }
      getchar();
  
  }
  </code></pre>