1、综合练习一:打印 ASC 码表在这个项目中,我们想去打印所有的ASCII码字符及相关联的十进制和二进制值。关于ASCIIASCII表示美国信息交换标准码,正如它的名字所暗示的, 它是由美国的一个代码指定的数字每个信息存储或传输计算机来完成。这里是关于ASCII码的重点:每个键盘字符都可以映射到数字从32127;数字从0 到 31用于特殊字符,如制表符、铃、换行符等;扩展ASCII范围从128 至255,含有专门128 个字符,如边框线等;扩展的ASCII字符是非标准化,可能会从一个操作系统类型到另一个(如PC 和MAC与Linux);标准的 ASCII 是标准化的,同样都可以跨越不同的操作系统
2、类型。最终结果第一步写出程序的基本框架任何 C 程序都具有以下的基本框架第二步添加一个具有一个变量的循环语句我们想去打印所有的标准和扩展 ASCII 码的值,这就意味着循环从 0 至 255/* Title : Print Standard and Extended ASCII chart* Source : print_ascii.c* Author : Some Student* Version : 1.0*/#include main()/* Title : Print Standard and Extended ASCII chart* Source : print_ascii.c*
3、Author : NJCIT* Version : 1.0*/#include main()int i;for (i=1; imain()int i;for (i=1; imain()int i;printf(“DEC HEX ASCIIn“);for (i=1; imain()int i;printf(“| DEC HEX ASC | DEC HEX ASC | DEC HEX ASC “);printf(“| DEC HEX ASC | DEC HEX ASC |n“);for (i=1; imain()int i, a;for (a=0; avoid pretty_line()int a
4、;for (a=0; a/* This function prints a line accros the screen.* The line can be one of the following types:* line_type = 0 - The top line* line_type = 1 - The middle line* line_type = 2 - the bottom line*/void pretty_line(int line_type)char left_char, right_char, mid_char;char ext_char;int a;/* Set l
5、eft, right and mid characters depending on line type */switch (line_type) case 0: /* Top line */left_char = 213;right_char = 184;mid_char = 209;break;case 1: /* Middle line */left_char = 198;right_char = 181;mid_char = 216;break;case 2: /* Bottom line */left_char = 212;right_char = 190;mid_char = 20
6、7;break;default: /* Invalid argument passed to us. */left_char = -;right_char = -;mid_char = +;for (a=0; a71; a+) ext_char = (a=0) ? left_char : (a=70) ? right_char : (a % 14= 0) ? mid_char : 205;printf(“%c“, ext_char);printf(“n“);left_char = 198;right_char = 181;mid_char = 216; break;case 2: /* Bot
7、tom line */left_char = 212;right_char = 190;mid_char = 207; break;default: /* Invalid argument passed to us. */left_char = -;right_char = -;mid_char = +;for (a=0; a71; a+) ext_char= (a=0)? left_char:(a=70)?right_char:(a % 14= 0) ? mid_char : 205;printf(“%c“, ext_char);printf(“n“);return;main()int i;
8、/* Print the top border line */pretty_line(0);/* Print the heading */printf(“| DEC HEX ASC | DEC HEX ASC | DEC HEX ASC “);printf(“| DEC HEX ASC | DEC HEX ASC |n“);/* Print the middle border line */pretty_line(1);/* Print the ASCII table */for (i=1; i=51; i+) if (i 32)printf(“| %3d %3x %3s “, i, i, “n/a“);elseprintf(“| %3d %3x %3c “, i, i, i);printf(“| %3d %3x %3c | %3d %3x %3c “, i+51, i+51, i+51, i+102, i+102, i+102);printf(“| %3d %3x %3c | %3d %3x %3c |n“, i+153, i+153, i+153, i+204, i+204, i+204);/* Print the bottom border line */pretty_line(2);return(0);