title: Using Arrow Keys in C
body: <p>I've finally got a hold of the Arrow Keys in C. I've found out how to have C detect them and have actually made a program of it.</p>
  
  <p>The problem is... The program is bugged. I don't know what I've done wrong.</p>
  
  <p>CODE:</p>
  
  <pre><code>#include &lt;stdio.h&gt;
  main()
  {
      char menitem[3][32], key, key2;
      int i = 0;
      strcpy(menitem[0], "Option 1 [X]");
      strcpy(menitem[1], "Option 2 [ ]");
      strcpy(menitem[2], "Option 3 [ ]");
      start:
      system("cls");
      printf("%s\n%s\n%s", menitem[0], menitem[1], menitem[2]);
      key = getch();
      key2 = 0;
      if(key = 0xE0)
      key2 = getch();
      ret:
      if(i == 0)
      {
           switch(key2)
           {
          case 80:
              strcat(menitem[0], "\b\b ]");
              i++;
              strcat(menitem[i], "\b\bX]");
              goto start;
          default: goto ret;
       }
  }
  else if(i == 2)
  {
       switch(key2)
      {
      case 72:
          strcat(menitem[2], "\b\b ]");
          i--;
          strcat(menitem[i], "\b\bX]");
          goto start;
          default: goto ret;
      }
  }
  else
  {
      switch(key2)
      {
          case 80:
          strcat(menitem[i], "\b\b ]");
          i++;
          strcat(menitem[i], "\b\bX]");
          goto start;
          case 72:
          strcat(menitem[i], "\b\b ]");
          i--;
          strcat(menitem[i], "\b\bX]");
          goto start;
          default: goto ret;
      }
  }
  }
  </code></pre>
  
  <p>Here's the problem:</p>
  
  <p>When I go up from Option 2, Option 3 turns into "X]". Any idea why?</p>
  
  <p>Try compiling it and keep on using the arrow keys. See what happens. Will appreciate any help given!</p>