you need a condition to break out of your while loop.
so like,
main()
{
   char ch = ' ';
   while (ch != 'q')
   {
      printf("Enter a character: \n");
      ch = getche();
      printf("\nThe code for %c is %d.\n", ch, ch);
   }
}
would break out if the entered char was 'q', or if you insist on while(1), you could use the "break" keyword:
main()
{
   while (1)
   {
      char ch;
      printf("Enter a character: \n");
      ch = getche();
      printf("\nThe code for %c is %d.\n", ch, ch);
      if (ch == 'q')
         break;       
   }
}