I'm beginner in C this is my code that prints ascii table in different representation such as decimal, hexadecimal, octal and binary. and I don't know how to reprint a statement (row) that shows what in column every 20 line or rows.
this is my code
#include <stdio.h>
#ifndef CHAR_BIT
#define CHAR_BIT 8
#endif
int main () {
unsigned char c = 0; /* for the character */
int n = 0; /* integer for the for loop Iteration */
printf_s("\nthis's ASCII table with all representations: \n");
printf_s("\n deci hex oct binary characters\n"); /* header for the table */
for (c = 0; c <= 255; c )
{
printf_s ("\n = %2X o \t", c, c, c, c); /* print Ascii using for loop with multi representations */
for (n = sizeof (c) * CHAR_BIT - 1; n >= 0; n--) /* method to convert decimal to base 2 (binary) */
printf_s ("%d", ((c >> n) & 0x1) ? 1 : 0);
printf_s("\", c);
putchar ('\n');
if(c==255)
break; /* to stop in 255 and not making infinite loop (because of unsigned char) */
}
putchar ('\n');
return 0;
}
this is how my output look like
deci hex oct binary characters
0 0 000 00000000
1 1 001 00000001 ☺
2 2 002 00000010 ☻
3 3 003 00000011 ♥
4 4 004 00000100 ♦
5 5 005 00000101 ♣
6 6 006 00000110 ♠
7 7 007 00000111
8 8 010 00001000
9 9 011 00001001
10 A 012 00001010
11 B 013 00001011 ♂
12 C 014 00001100 ♀
13 D 015 00001101
14 E 016 00001110 ♫
15 F 017 00001111 ☼
16 10 020 00010000 ►
17 11 021 00010001 ◄
18 12 022 00010010 ↕
19 13 023 00010011 ‼
20 14 024 00010100 ¶
21 15 025 00010101 §
22 16 026 00010110 ▬
23 17 027 00010111 ↨
24 18 030 00011000 ↑
25 19 031 00011001 ↓
26 1A 032 00011010 →
27 1B 033 00011011
8 1C 034 00011100 ∟
29 1D 035 00011101 ↔
30 1E 036 00011110 ▲
31 1F 037 00011111 ▼
32 20 040 00100000
33 21 041 00100001 !
34 22 042 00100010 "
35 23 043 00100011 #
36 24 044 00100100 $
37 25 045 00100101 %
38 26 046 00100110 &
39 27 047 00100111 '
40 28 050 00101000 (
41 29 051 00101001 )
42 2A 052 00101010 *
43 2B 053 00101011
44 2C 054 00101100 ,
45 2D 055 00101101 -
46 2E 056 00101110 .
47 2F 057 00101111 /
48 30 060 00110000 0
49 31 061 00110001 1
50 32 062 00110010 2
51 33 063 00110011 3
52 34 064 00110100 4
53 35 065 00110101 5
54 36 066 00110110 6
55 37 067 00110111 7
56 38 070 00111000 8
57 39 071 00111001 9
58 3A 072 00111010 :
59 3B 073 00111011 ;
60 3C 074 00111100 <
61 3D 075 00111101 =
62 3E 076 00111110 >
63 3F 077 00111111 ?
64 40 100 01000000 @
65 41 101 01000001 A
66 42 102 01000010 B
67 43 103 01000011 C
68 44 104 01000100 D
69 45 105 01000101 E
70 46 106 01000110 F
71 47 107 01000111 G
72 48 110 01001000 H
73 49 111 01001001 I
74 4A 112 01001010 J
75 4B 113 01001011 K
76 4C 114 01001100 L
77 4D 115 01001101 M
78 4E 116 01001110 N
79 4F 117 01001111 O
80 50 120 01010000 P
81 51 121 01010001 Q
82 52 122 01010010 R
83 53 123 01010011 S
84 54 124 01010100 T
85 55 125 01010101 U
86 56 126 01010110 V
87 57 127 01010111 W
88 58 130 01011000 X
89 59 131 01011001 Y
90 5A 132 01011010 Z
91 5B 133 01011011 [
92 5C 134 01011100 \
93 5D 135 01011101 ]
94 5E 136 01011110 ^
95 5F 137 01011111 _
96 60 140 01100000 `
97 61 141 01100001 a
98 62 142 01100010 b
99 63 143 01100011 c
100 64 144 01100100 d
101 65 145 01100101 e
102 66 146 01100110 f
103 67 147 01100111 g
104 68 150 01101000 h
105 69 151 01101001 i
106 6A 152 01101010 j
107 6B 153 01101011 k
108 6C 154 01101100 l
109 6D 155 01101101 m
110 6E 156 01101110 n
111 6F 157 01101111 o
112 70 160 01110000 p
113 71 161 01110001 q
114 72 162 01110010 r
115 73 163 01110011 s
116 74 164 01110100 t
117 75 165 01110101 u
118 76 166 01110110 v
119 77 167 01110111 w
120 78 170 01111000 x
121 79 171 01111001 y
122 7A 172 01111010 z
123 7B 173 01111011 {
124 7C 174 01111100 |
125 7D 175 01111101 }
126 7E 176 01111110 ~
127 7F 177 01111111 ⌂
128 80 200 10000000 Ç
129 81 201 10000001 ü
130 82 202 10000010 é
131 83 203 10000011 â
132 84 204 10000100 ä
133 85 205 10000101 à
134 86 206 10000110 å
135 87 207 10000111 ç
136 88 210 10001000 ê
137 89 211 10001001 ë
138 8A 212 10001010 è
139 8B 213 10001011 ï
140 8C 214 10001100 î
141 8D 215 10001101 ì
142 8E 216 10001110 Ä
143 8F 217 10001111 Å
144 90 220 10010000 É
145 91 221 10010001 æ
146 92 222 10010010 Æ
147 93 223 10010011 ô
148 94 224 10010100 ö
149 95 225 10010101 ò
150 96 226 10010110 û
151 97 227 10010111 ù
152 98 230 10011000 ÿ
153 99 231 10011001 Ö
154 9A 232 10011010 Ü
155 9B 233 10011011 ¢
156 9C 234 10011100 £
157 9D 235 10011101 ¥
158 9E 236 10011110 ₧
159 9F 237 10011111 ƒ
160 A0 240 10100000 á
161 A1 241 10100001 í
162 A2 242 10100010 ó
163 A3 243 10100011 ú
164 A4 244 10100100 ñ
165 A5 245 10100101 Ñ
166 A6 246 10100110 ª
167 A7 247 10100111 º
168 A8 250 10101000 ¿
169 A9 251 10101001 ⌐
170 AA 252 10101010 ¬
171 AB 253 10101011 ½
172 AC 254 10101100 ¼
173 AD 255 10101101 ¡
174 AE 256 10101110 «
175 AF 257 10101111 »
176 B0 260 10110000 ░
177 B1 261 10110001 ▒
178 B2 262 10110010 ▓
179 B3 263 10110011 │
180 B4 264 10110100 ┤
181 B5 265 10110101 ╡
182 B6 266 10110110 ╢
183 B7 267 10110111 ╖
184 B8 270 10111000 ╕
185 B9 271 10111001 ╣
186 BA 272 10111010 ║
187 BB 273 10111011 ╗
188 BC 274 10111100 ╝
189 BD 275 10111101 ╜
190 BE 276 10111110 ╛
191 BF 277 10111111 ┐
192 C0 300 11000000 └
193 C1 301 11000001 ┴
194 C2 302 11000010 ┬
195 C3 303 11000011 ├
196 C4 304 11000100 ─
197 C5 305 11000101 ┼
198 C6 306 11000110 ╞
199 C7 307 11000111 ╟
200 C8 310 11001000 ╚
201 C9 311 11001001 ╔
202 CA 312 11001010 ╩
203 CB 313 11001011 ╦
204 CC 314 11001100 ╠
205 CD 315 11001101 ═
206 CE 316 11001110 ╬
207 CF 317 11001111 ╧
208 D0 320 11010000 ╨
209 D1 321 11010001 ╤
210 D2 322 11010010 ╥
211 D3 323 11010011 ╙
212 D4 324 11010100 ╘
213 D5 325 11010101 ╒
214 D6 326 11010110 ╓
215 D7 327 11010111 ╫
216 D8 330 11011000 ╪
217 D9 331 11011001 ┘
218 DA 332 11011010 ┌
219 DB 333 11011011 █
220 DC 334 11011100 ▄
221 DD 335 11011101 ▌
222 DE 336 11011110 ▐
223 DF 337 11011111 ▀
224 E0 340 11100000 α
225 E1 341 11100001 ß
226 E2 342 11100010 Γ
227 E3 343 11100011 π
228 E4 344 11100100 Σ
229 E5 345 11100101 σ
230 E6 346 11100110 µ
231 E7 347 11100111 τ
232 E8 350 11101000 Φ
233 E9 351 11101001 Θ
234 EA 352 11101010 Ω
235 EB 353 11101011 δ
236 EC 354 11101100 ∞
237 ED 355 11101101 φ
238 EE 356 11101110 ε
239 EF 357 11101111 ∩
240 F0 360 11110000 ≡
241 F1 361 11110001 ±
242 F2 362 11110010 ≥
243 F3 363 11110011 ≤
244 F4 364 11110100 ⌠
245 F5 365 11110101 ⌡
246 F6 366 11110110 ÷
247 F7 367 11110111 ≈
248 F8 370 11111000 °
249 F9 371 11111001 ∙
250 FA 372 11111010 ·
251 FB 373 11111011 √
252 FC 374 11111100 ⁿ
253 FD 375 11111101 ²
254 FE 376 11111110 ■
255 FF 377 11111111
And the output I want it to be look like this
deci hex oct binary characters
0 0 000 00000000
1 1 001 00000001 ☺
2 2 002 00000010 ☻
3 3 003 00000011 ♥
4 4 004 00000100 ♦
5 5 005 00000101 ♣
6 6 006 00000110 ♠
7 7 007 00000111
8 8 010 00001000
9 9 011 00001001
10 A 012 00001010
11 B 013 00001011 ♂
12 C 014 00001100 ♀
13 D 015 00001101
14 E 016 00001110 ♫
15 F 017 00001111 ☼
16 10 020 00010000 ►
17 11 021 00010001 ◄
18 12 022 00010010 ↕
19 13 023 00010011 ‼
20 14 024 00010100 ¶
deci hex oct binary characters
21 15 025 00010101 §
22 16 026 00010110 ▬
23 17 027 00010111 ↨
24 18 030 00011000 ↑
25 19 031 00011001 ↓
26 1A 032 00011010 →
27 1B 033 00011011
28 1C 034 00011100 ∟
29 1D 035 00011101 ↔
30 1E 036 00011110 ▲
31 1F 037 00011111 ▼
32 20 040 00100000
33 21 041 00100001 !
34 22 042 00100010 "
35 23 043 00100011 #
36 24 044 00100100 $
37 25 045 00100101 %
38 26 046 00100110 &
39 27 047 00100111 '
40 28 050 00101000 (
deci hex oct binary characters
41 29 051 00101001 )
42 2A 052 00101010 *
43 2B 053 00101011
44 2C 054 00101100 ,
45 2D 055 00101101 -
46 2E 056 00101110 .
47 2F 057 00101111 /
48 30 060 00110000 0
49 31 061 00110001 1
50 32 062 00110010 2
51 33 063 00110011 3
52 34 064 00110100 4
53 35 065 00110101 5
54 36 066 00110110 6
55 37 067 00110111 7
56 38 070 00111000 8
57 39 071 00111001 9
58 3A 072 00111010 :
59 3B 073 00111011 ;
60 3C 074 00111100 <
deci hex oct binary characters
61 3D 075 00111101 =
62 3E 076 00111110 >
63 3F 077 00111111 ?
64 40 100 01000000 @
65 41 101 01000001 A
66 42 102 01000010 B
67 43 103 01000011 C
68 44 104 01000100 D
69 45 105 01000101 E
70 46 106 01000110 F
71 47 107 01000111 G
72 48 110 01001000 H
73 49 111 01001001 I
74 4A 112 01001010 J
75 4B 113 01001011 K
76 4C 114 01001100 L
77 4D 115 01001101 M
78 4E 116 01001110 N
79 4F 117 01001111 O
80 50 120 01010000 P
deci hex oct binary characters
81 51 121 01010001 Q
82 52 122 01010010 R
83 53 123 01010011 S
84 54 124 01010100 T
85 55 125 01010101 U
86 56 126 01010110 V
87 57 127 01010111 W
88 58 130 01011000 X
89 59 131 01011001 Y
90 5A 132 01011010 Z
91 5B 133 01011011 [
92 5C 134 01011100 \
93 5D 135 01011101 ]
94 5E 136 01011110 ^
95 5F 137 01011111 _
96 60 140 01100000 `
97 61 141 01100001 a
98 62 142 01100010 b
99 63 143 01100011 c
100 64 144 01100100 d
deci hex oct binary characters
101 65 145 01100101 e
102 66 146 01100110 f
103 67 147 01100111 g
104 68 150 01101000 h
105 69 151 01101001 i
106 6A 152 01101010 j
107 6B 153 01101011 k
108 6C 154 01101100 l
109 6D 155 01101101 m
110 6E 156 01101110 n
111 6F 157 01101111 o
112 70 160 01110000 p
113 71 161 01110001 q
114 72 162 01110010 r
115 73 163 01110011 s
116 74 164 01110100 t
117 75 165 01110101 u
118 76 166 01110110 v
119 77 167 01110111 w
120 78 170 01111000 x
deci hex oct binary characters
121 79 171 01111001 y
122 7A 172 01111010 z
123 7B 173 01111011 {
124 7C 174 01111100 |
125 7D 175 01111101 }
126 7E 176 01111110 ~
127 7F 177 01111111 ⌂
128 80 200 10000000 Ç
129 81 201 10000001 ü
130 82 202 10000010 é
131 83 203 10000011 â
132 84 204 10000100 ä
133 85 205 10000101 à
134 86 206 10000110 å
135 87 207 10000111 ç
136 88 210 10001000 ê
137 89 211 10001001 ë
138 8A 212 10001010 è
139 8B 213 10001011 ï
140 8C 214 10001100 î
deci hex oct binary characters
141 8D 215 10001101 ì
142 8E 216 10001110 Ä
143 8F 217 10001111 Å
144 90 220 10010000 É
145 91 221 10010001 æ
146 92 222 10010010 Æ
147 93 223 10010011 ô
148 94 224 10010100 ö
149 95 225 10010101 ò
150 96 226 10010110 û
151 97 227 10010111 ù
152 98 230 10011000 ÿ
153 99 231 10011001 Ö
154 9A 232 10011010 Ü
155 9B 233 10011011 ¢
156 9C 234 10011100 £
157 9D 235 10011101 ¥
158 9E 236 10011110 ₧
159 9F 237 10011111 ƒ
160 A0 240 10100000 á
deci hex oct binary characters
161 A1 241 10100001 í
162 A2 242 10100010 ó
163 A3 243 10100011 ú
164 A4 244 10100100 ñ
165 A5 245 10100101 Ñ
166 A6 246 10100110 ª
167 A7 247 10100111 º
168 A8 250 10101000 ¿
169 A9 251 10101001 ⌐
170 AA 252 10101010 ¬
171 AB 253 10101011 ½
172 AC 254 10101100 ¼
173 AD 255 10101101 ¡
174 AE 256 10101110 «
175 AF 257 10101111 »
176 B0 260 10110000 ░
177 B1 261 10110001 ▒
178 B2 262 10110010 ▓
179 B3 263 10110011 │
180 B4 264 10110100 ┤
deci hex oct binary characters
181 B5 265 10110101 ╡
182 B6 266 10110110 ╢
183 B7 267 10110111 ╖
184 B8 270 10111000 ╕
185 B9 271 10111001 ╣
186 BA 272 10111010 ║
187 BB 273 10111011 ╗
188 BC 274 10111100 ╝
189 BD 275 10111101 ╜
190 BE 276 10111110 ╛
191 BF 277 10111111 ┐
192 C0 300 11000000 └
193 C1 301 11000001 ┴
194 C2 302 11000010 ┬
195 C3 303 11000011 ├
196 C4 304 11000100 ─
197 C5 305 11000101 ┼
198 C6 306 11000110 ╞
199 C7 307 11000111 ╟
200 C8 310 11001000 ╚
deci hex oct binary characters
201 C9 311 11001001 ╔
202 CA 312 11001010 ╩
203 CB 313 11001011 ╦
204 CC 314 11001100 ╠
205 CD 315 11001101 ═
206 CE 316 11001110 ╬
207 CF 317 11001111 ╧
208 D0 320 11010000 ╨
209 D1 321 11010001 ╤
210 D2 322 11010010 ╥
211 D3 323 11010011 ╙
212 D4 324 11010100 ╘
213 D5 325 11010101 ╒
214 D6 326 11010110 ╓
215 D7 327 11010111 ╫
216 D8 330 11011000 ╪
217 D9 331 11011001 ┘
218 DA 332 11011010 ┌
219 DB 333 11011011 █
220 DC 334 11011100 ▄
deci hex oct binary characters
221 DD 335 11011101 ▌
222 DE 336 11011110 ▐
223 DF 337 11011111 ▀
224 E0 340 11100000 α
225 E1 341 11100001 ß
226 E2 342 11100010 Γ
227 E3 343 11100011 π
228 E4 344 11100100 Σ
229 E5 345 11100101 σ
230 E6 346 11100110 µ
231 E7 347 11100111 τ
232 E8 350 11101000 Φ
233 E9 351 11101001 Θ
234 EA 352 11101010 Ω
235 EB 353 11101011 δ
236 EC 354 11101100 ∞
237 ED 355 11101101 φ
238 EE 356 11101110 ε
239 EF 357 11101111 ∩
240 F0 360 11110000 ≡
deci hex oct binary characters
241 F1 361 11110001 ±
242 F2 362 11110010 ≥
243 F3 363 11110011 ≤
244 F4 364 11110100 ⌠
245 F5 365 11110101 ⌡
246 F6 366 11110110 ÷
247 F7 367 11110111 ≈
248 F8 370 11111000 °
249 F9 371 11111001 ∙
250 FA 372 11111010 ·
251 FB 373 11111011 √
252 FC 374 11111100 ⁿ
253 FD 375 11111101 ²
254 FE 376 11111110 ■
255 FF 377 11111111
CodePudding user response:
This is working for me fine.
#include <stdio.h>
#ifndef CHAR_BIT
#define CHAR_BIT 8
#endif
int main () {
unsigned char c = 0; /* for the character */
int n = 0; /* integer for the for loop Iteration */
printf("\nthis's ASCII table with all representations: \n");
for (c = 0; c <= 255; c )
{
if (c%20 == 0)
printf("\n deci hex oct binary characters\n");
printf ("\n = %2X o \t", c, c, c); /* print Ascii using for loop with multi representations */
for (n = sizeof (c) * CHAR_BIT - 1; n >= 0; n--){ /* method to convert decimal to base 2 (binary) */
printf ("%d", ((c >> n) & 0x1) ? 1 : 0);
}
printf("\", c);
putchar ('\n');
if(c==255)
break; /* to stop in 255 and not making infinite loop (because of unsigned char) */
}
putchar ('\n');
return 0;
}