-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathi.c
More file actions
56 lines (44 loc) · 720 Bytes
/
i.c
File metadata and controls
56 lines (44 loc) · 720 Bytes
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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
#include <stdio.h>
#include <ctype.h>
void process_str(char *);
void print_integer(int);
int
main(int argc, char **argv)
{
for (int i = 1; i < argc; i++)
{
process_str(argv[i]);
}
if (1 < argc) return 0;
char buffer[255];
while (fgets(buffer, sizeof(buffer), stdin))
{
process_str(buffer);
}
return 0;
}
void
process_str(char *str)
{
int integer = 0;
char character = 0;
if (1 == sscanf(str, "%i", &integer))
print_integer(integer);
else
{
int k = 0;
while (1 == sscanf(str + k, "%c", &character))
{
print_integer((int) character);
k++;
}
}
}
void
print_integer(int i)
{
printf("0x%02x 0%03o %3d", i, i, i);
if (isprint(i))
printf(" %c", (char) i);
printf("\n");
}