Why am I getting the wrong output? I have a feeling it has something to do with using type char vs. int....but im not specifically too sure. Please help!
1.
blade71(130)% gcc -o vt visitype.c
2.
blade71(131)% vt < vt.in > vt.out
3.
blade71(132)% cat vt.out
4.
The code 55 represents U
5.
The code 4c represents L
6.
The code 56 represents V
7.
The code 53 represents S
8.
The code 41 represents A
9.
The code 20 represents SP
10.
The code 4e represents N
11.
The code 53 represents S
12.
The code 45 represents E
13.
The code 0 represents NUL
14.
The code 4e represents N
15.
The code 58 represents X
16.
blade71(133)% cat vt.in
17.
}~a,bzZ
18.
blade71(134)% od -x vt.in
19.
0000000 0102 7d7e 612c 627a 5c7f 5a0a
20.
0000014
21.
blade71(135)% cat visitype.c
22.
#include <stdio.h>
23.
#define MAX 1000
24.
25.
void aVal(char asciiname[], char S[]);
26.
27.
main ()
28.
{
29.
int i, c, j;
30.
char asciiname[] =
31.
"NUL\0" "SOH\0" "STX\0" "ETX\0" "EOT\0" "ENQ\0" "ACK\0" "BEL\0"
32.
" BS\0" " HT\0" " NL\0" " VT\0" " NP\0" " CR\0" " SO\0" " SI\0"
33.
"DLE\0" "DC1\0" "DC2\0" "DC3\0" "DC4\0" "NAK\0" "SYN\0" "ETB\0"
34.
"CAN\0" " EM\0" "SUB\0" "ESC\0" " FS\0" " GS\0" " RS\0" " VS\0"
35.
" SP\0" " !\0" " \"\0" " #\0" " $\0" " %\0" " &\0" " '\0"
36.
" (\0" " )\0" " *\0" " +\0" " ,\0" " -\0" " .\0" " /\0"
37.
" 0\0" " 1\0" " 2\0" " 3\0" " 4\0" " 5\0" " 6\0" " 7\0"
38.
" 8\0" " 9\0" " :\0" " ;\0" " <\0" " =\0" " >\0" " ?\0"
39.
" @\0" " A\0" " B\0" " C\0" " D\0" " E\0" " F\0" " G\0"
40.
" H\0" " I\0" " J\0" " K\0" " L\0" " M\0" " N\0" " O\0"
41.
" P\0" " Q\0" " R\0" " S\0" " T\0" " U\0" " V\0" " W\0"
42.
" X\0" " Y\0" " Z\0" " [\0" " \\\0" " ]\0" " ^\0" " _\0"
43.
" `\0" " a\0" " b\0" " c\0" " d\0" " e\0" " f\0" " g\0"
44.
" h\0" " i\0" " j\0" " k\0" " l\0" " m\0" " n\0" " o\0"
45.
" p\0" " q\0" " r\0" " s\0" " t\0" " u\0" " v\0" " w\0"
46.
" x\0" " y\0" " z\0" " {\0" " |\0" " }\0" " ~\0" "DEL\0"
47.
;
48.
char S[MAX], *p1;
49.
p1 = S;
50.
c = getchar();
51.
for (i = 0; c!=EOF; c=getchar())
52.
{
53.
S[i] = c;
54.
i++;
55.
}
56.
S[i] = '\0';
57.
aVal (asciiname, S);
58.
}
59.
void aVal(char asciiname[], char S[])
60.
{
61.
int i, j;
62.
int k;
63.
i = 0;
64.
k = S[i];
65.
for ( i = 0; k!='\0'; k = S[i])
66.
{
67.
j = asciiname[k];
68.
printf("The code %3x represents %s\n", j, &asciiname[4*j]);
69.
i++;
70.
}
71.
S[i] = '\0';
72.
73.
}