File: test.c

package info (click to toggle)
omega-rpg 1%3A0.90-pa9-21
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 2,780 kB
  • sloc: ansic: 38,528; makefile: 112; sh: 17
file content (37 lines) | stat: -rw-r--r-- 753 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
#include <stdio.h>

int key_to_index(key)
char key;
{
  if ( key >= '0' && key <= '9' )
      return (int)(key - '0');
  else if ( key >= 'a' && key <= 'c' )
      return (int)(key - 'a') + 10;
  else if ( key >= 'e' && key <= 'f' )
      return (int)(key - 'e') + 13;
  else return -100;
}

char index_to_key(index)
int index;
{
  if ( index >= 0 && index <= 9 )
      return (char)(index + '0');
  else if ( index >= 10 && index <= 12 )
      return (char)(index - 10 + 'a');
  else if ( index >= 13 && index <= 14 )
      return (int)(index - 13 + 'e');
  else
      /* huh? */
      return '?';
}

int main()
{
  int i;
  for ( i=0; i<16; i++ )
  {
    printf( "%d ==> %c:%d\n",
           i, index_to_key(i), key_to_index(index_to_key(i)) );
  }
}