/home/toolbox/public_html/solutions/104/10473/a.c
1 #include <stdio.h>
2 #include <string.h>
3 #include <sys/types.h>
4 #include <sys/stat.h>
5 #include <fcntl.h>
6 #include <stdint.h>
7 #include <math.h>
8 #include <stdlib.h>
9
10 #define TRUE (1 == 1)
11 #define FALSE (1 != 1)
12
13 #define DEBUG if (FALSE)
14
15 #define MAX_LINE 257
16
17 /*
18 * Author: Isaac Traxler
19 * Date: 2017-01-22
20 * Purpose: fun
21 * Problem: 10473 - Simple base conversion
22 */
23
24 /*
25 * This template reads lines of data at a time until end of file.
26 */
27
28 char line[MAX_LINE];
29
30 void init()
31 {
32 /* FUNCTION init */
33 } /* FUNCTION init */
34
35 void dump()
36 {
37 /* FUNCTION dump */
38 } /* FUNCTION dump */
39
40 int getInput()
41 {
42 /* FUNCTION getInput */
43 int dataReadFlag;
44
45 fgets(line, MAX_LINE, stdin);
46 if (feof(stdin))
47 dataReadFlag = FALSE;
48 else
49 {
50 /* something to read */
51 line[strlen(line)-1] = 0;
52 dataReadFlag = ('-' != line[0]);
53 } /* something to read */
54 return (dataReadFlag);
55 } /* FUNCTION getInput */
56
57 void process()
58 {
59 /* FUNCTION process */
60 int num;
61
62 if ('x' == line[1])
63 {
64 /* we have a hex number */
65 sscanf(line, " %x ", &num);
66 printf("%d\n", num);
67 } /* we have a hex number */
68 else
69 {
70 /* must be a decimal */
71 sscanf(line, " %d ", &num);
72 printf("0x%X\n", num);
73 } /* must be a decimal */
74 } /* FUNCTION process */
75
76 int main()
77 {
78 /* main */
79 int moreToDo;
80
81 init();
82 moreToDo = getInput();
83 while (moreToDo)
84 {
85 /* while */
86 process();
87 moreToDo = getInput();
88 } /* while */
89
90 return EXIT_SUCCESS;
91 } /* main */
92