I 4 003 4 30 1 ASCII ( ) 0 17 0 NUL 16 DLE SP 0 @ P 3 48 64 80 96 11 p 1 SOH 17 DC1! 1 A Q a 33 49 65 81 97 113 q STX 18 DC " B R b 34 50 66 8 98 114 r 3 ETX 19 DC3 # 3 C S c 35 51 67 83 99 115 s 4 EOT 0 DC4 $ 4 D T d 36 5 68 84 100 116 t 5 ENQ 1 NAK % 5 E U e 37 53 69 85 101 117 u 6 ACK SYN & 6 F V f 38 54 70 86 10 118 v BEL 7 3 ETB 7 G W g 39 55 71 87 103 119 w BS 8 4 CAN ( 8 H X h 40 56 7 88 104 10 x HT EM ) 9 I Y i 9 5 41 57 73 89 105 11 y 1 ASCII LF 10 6 SUB * : J Z j 4 58 74 90 106 1 z VT 11 7 ESC + ; K [ k 43 59 75 91 107 13 { 1 13 14 15 FF CR SO SI 8 9 30 31 FS GS RS US 44 45 46 47, -. / 60 61 6 63 < = >? 76 77 78 79 L M N O 9 93 94 95 \ ] ^ _ 108 109 110 111 l m n o 14 15 16 17 } ~ DEL ( ) ASCII ( ) ASCII ASCII ASCII 0 31 17 ( ) 3 SP 1 (Space) 1 SP 33 16 ( ) ISO 646-US ISO 646-US ISO 646-JP JIS X 001 Roman 9 16 ISO 646-US (ASCII ) ISO 646-JP (JIS X 001 Roman) ISO 646-JP (JIS X 001 Roman) 9 ( ) 16 ( ) \ ( ) ~ ( ) C 1 4 1
NUL Null C 3 \0 C BEL Bell \a BS Backspace \b ( )1 HT Horizontal Tabulation \t ( ) ( 8 ) LF Line feed 4 \n C 1 VT Vertical Tabulation \v ( ) FF Form Feed 5 \f CR Carriage Return \r C.1 printf 1 byte ASCII 1 byte (= 8 bit) printf printf %c ( ) printf ascii.c 3 16 1 8 1 #include <stdio.h> 3 int main() 4 { 5 int c; 6 7 for (c = 3; c <= 16; c++) { 8 printf("%3d=%c", c, c); 9 if (c%8 == 7 c == 16) 10 printf("\n"); 11 else 1 printf(" "); 13 } 14 return 0; 15 } ascii.c 8 printf %3d %c c %3d c ( ) %c c 4 3. 3 SP ( ) 4 New Line 5 4
1 s1609h017% cc ascii.c -o ascii s1609h017%./ascii 3= 33=! 34=" 35=# 36=$ 37=% 38=& 39= 40=( 41=) 4=* 43=+ 44=, 45=- 46=. 47=/ 48=0 49=1 50= 51=3 5=4 53=5 54=6 55=7 56=8 57=9 58=: 59=; 60=< 61== 6=> 63=? 64=@ 65=A 66=B 67=C 68=D 69=E 70=F 71=G 7=H 73=I 74=J 75=K 76=L 77=M 78=N 79=O 80=P 81=Q 8=R 83=S 84=T 85=U 86=V 87=W 88=X 89=Y 90=Z 91=[ 9=\ 93=] 94=^ 95=_ 96= 97=a 98=b 99=c 100=d 101=e 10=f 103=g 104=h 105=i 106=j 107=k 108=l 109=m 110=n 111=o 11=p 113=q 114=r 115=s 116=t 117=u 118=v 119=w 10=x 11=y 1=z 13={ 14= 15=} 16=~ s1609h017% ascii.c. C ( ) (int ) C A A (ASCII 65) 4 C \n ( ) \ \ ( ) \\ ASCII ascii.c ascii.c 1 #include <stdio.h> 3 int main() 4 { 5 int c; 6 7 for (c = ; c <= ~ ; c++) 8 printf("%3d=%c%c", c, c, (c%8 == 7 c == ~ )? \n : ); 9 return 0; 10 }.3 char ASCII 0 17 C char char 1 byte (= 8 4 3
bit) 6 18 17 7 0 55 char char int.4 char char int C char char ch; 1 char 1 char ( ) int ascii.c ascii.c 5 int c; char c; c ( ) char printf char char int int printf.5 scanf 1 byte scanf 1 byte %c ( ) (scanf ) %c char (char ) chars.c 9 scanf char ( ) 5 char c; int c; 1 #include <stdio.h> 3 int main() 4 { 5 char c; 6 7 printf(" = "); 8 do { 9 scanf("%c", &c); 10 printf("%3d=%c\n", c, c); 11 } while (c!= \n ); 1 return 0; 13 } chars.c 6 C 7 C 17 17 4 4
s1609h017%./chars = This is a test. 84=T 104=h 105=i 115=s 3= 105=i 115=s 3= 97=a 3= 116=t 101=e 115=s 116=t 46=. 10= chars.c s1609h017% chars.c (Enter) chars 7 printf = (Enter) 9 scanf This is a test. (Enter) T 16 scanf T c main scanf scanf %d %f %lf () ( ) %c 1 %c " %c" scanf ( ) 3 othello09.c othello08.c (4 11 ) 1 8 a h * othello09.c 1 #include <stdio.h> 3 #define BLACK (1) /* */ 4 #define WHITE (-BLACK) /* */ 5 #define NONE (0) /* */ 4 5
6 #define OPPONENT(t) (-(t)) /* t */ 7 #define BOARD_SIZE (8) /* */ 8 9 /* */ 10 void reset(int b[][board_size]) 11 { 1 int x, y; 13 14 /* */ 15 for (x = 0; x < BOARD_SIZE; x++) 16 for (y = 0; y < BOARD_SIZE; y++) 17 b[x][y] = NONE; 18 /* 4 */ 19 b[board_size/-1][board_size/-1] = WHITE; 0 b[board_size/-1][board_size/] = BLACK; 1 b[board_size/][board_size/-1] = BLACK; b[board_size/][board_size/] = WHITE; 3 } 4 5 /* */ 6 void showboard(int b[][board_size]) 7 { 8 int x, y; 9 30 /* */ 31 for (x = 0; x < BOARD_SIZE; x++) *3 printf(" %c", x + a ); 33 printf("\n"); 34 /* */ 35 for (y = 0; y < BOARD_SIZE; y++) { *36 printf("%c", y + 1 ); 37 for (x = 0; x < BOARD_SIZE; x++) { 38 if (b[x][y] == BLACK) 39 printf(" "); 40 else if (b[x][y] == WHITE) 41 printf(" "); 4 43 else printf(" "); 44 45 } printf("\n"); 46 } 47 } 48 49 /* */ 50 void inputmove(int b[][board_size], int turn) 51 { *5 char ch; 53 int x, y; 54 55 56 while (1) { /* */ 57 *58 do { ch = ; 59 printf(" = "); *60 scanf(" %c", &ch); *61 x = ch - a ; *6 } while (x < 0 BOARD_SIZE <= x); 63 /* */ 64 *65 do { ch = ; 66 printf(" = "); *67 scanf(" %c", &ch); *68 y = ch - 1 ; 4 6
*69 } while (y < 0 BOARD_SIZE <= y); *70 if (b[x][y] == NONE) 71 break; 7 printf(" \n"); 73 74 } /* */ *75 b[x][y] = turn; 76 } 77 78 int main() 79 { 80 /* (BLACK/WHITE/NONE) */ 81 int board[board_size][board_size]; 8 /* */ 83 int turn = BLACK; 84 85 reset(board); 86 87 while (1) { showboard(board); 88 inputmove(board, turn); 89 turn = OPPONENT(turn); 90 } 91 /* */ 9 return 0; 93 } ASCII a h 1 8 s1609h017%./othello09 = c = = x = g = 4 othello09 4 7
= d = 0 = 5 = d = 7 = ^C s1609h017% 4 4.1 othello09.c 8 mprog1 othello09.c mprog1 Prog1 4. 1 othello09.c othello10.c othello10.c inputmove 1 a h 1 8 d4 ( ) char ch1 ch scanf 9 scanf(" %c %c", &ch1, &ch); scanf %c 8 othello08.c 9 scanf(" %c", &ch1); scanf(" %c", &ch); 4 8
s1609h017%./othello10 = d4 = d0 = d1 = x7 = g7 = ^C s1609h017% othello10 4.3 othello10.c othello11.c othello11.c inputmove s1609h017%./othello11 othello11 4 9
= d = g5 = 9e = 8e = ^C s1609h017% othello11.c getchar 1 q I 4 4 10
: othello08.c othello08.c 1 #include <stdio.h> 3 #define BLACK (1) /* */ 4 #define WHITE (-BLACK) /* */ 5 #define NONE (0) /* */ 6 #define OPPONENT(t) (-(t)) /* t */ 7 #define BOARD_SIZE (8) /* */ 8 9 /* */ 10 void reset(int b[][board_size]) 11 { 1 int x, y; 13 14 /* */ 15 for (x = 0; x < BOARD_SIZE; x++) 16 for (y = 0; y < BOARD_SIZE; y++) 17 b[x][y] = NONE; 18 /* 4 */ 19 b[board_size/-1][board_size/-1] = WHITE; 0 b[board_size/-1][board_size/] = BLACK; 1 b[board_size/][board_size/-1] = BLACK; b[board_size/][board_size/] = WHITE; 3 } 4 5 /* */ 6 void showboard(int b[][board_size]) 7 { 8 int x, y; 9 30 /* */ 31 for (x = 0; x < BOARD_SIZE; x++) 3 printf(" %d", x+1); 33 printf("\n"); 34 /* */ 35 for (y = 0; y < BOARD_SIZE; y++) { 36 printf("%d", y+1); 37 for (x = 0; x < BOARD_SIZE; x++) { 38 if (b[x][y] == BLACK) 39 printf(" "); 40 else if (b[x][y] == WHITE) 41 printf(" "); 4 else 43 printf(" "); 44 } 45 printf("\n"); 46 } 47 } 48 49 /* */ 50 void inputmove(int b[][board_size], int turn) 51 { 5 int x, y; 53 54 while (1) { 55 /* */ 56 do { 4 11
57 x = 0; 58 printf(" = "); 59 scanf("%d", &x); 60 } while (x <= 0 BOARD_SIZE < x); 61 /* */ 6 do { 63 y = 0; 64 printf(" = "); 65 scanf("%d", &y); 66 } while (y <= 0 BOARD_SIZE < y); 67 if (b[x-1][y-1] == NONE) 68 break; 69 printf(" \n"); 70 } 71 /* */ 7 b[x-1][y-1] = turn; 73 } 74 75 int main() 76 { 77 /* (BLACK/WHITE/NONE) */ 78 int board[board_size][board_size]; 79 /* */ 80 int turn = BLACK; 81 8 reset(board); 83 while (1) { 84 showboard(board); 85 inputmove(board, turn); 86 turn = OPPONENT(turn); 87 } 88 /* */ 89 return 0; 90 } 4 1