Document of c-modernization-kit (calc) 1.0.0
Loading...
Searching...
No Matches
calc.c
Go to the documentation of this file.
1
16
17#include <libcalc.h>
18#include <console-util.h>
19#include <stdio.h>
20#include <stdlib.h>
21
43int main(int argc, char *argv[])
44{
45 console_init();
46
47 if (argc != 4)
48 {
49 fprintf(stderr, "Usage: %s <arg1> <arg2> <arg3>\n", argv[0]);
50 console_dispose();
51 return 1;
52 }
53
54 if (argv[2][0] == 0x00 || argv[2][1] != 0x00)
55 {
56 fprintf(stderr, "Usage: %s <arg1> <arg2> <arg3>\n", argv[0]);
57 console_dispose();
58 return 1;
59 }
60
61 int arg1 = atoi(argv[1]);
62 int arg3 = atoi(argv[3]);
63 int result;
64
65 int kind;
66 switch (argv[2][0])
67 {
68 case '+':
69 kind = CALC_KIND_ADD;
70 break;
71 case '-':
72 kind = CALC_KIND_SUBTRACT;
73 break;
74 case 'x':
75 kind = CALC_KIND_MULTIPLY;
76 break;
77 case '/':
78 kind = CALC_KIND_DIVIDE;
79 break;
80 default:
81 fprintf(stderr, "Usage: %s <num1> <+|-|x|/> <num2>\n", argv[0]);
82 console_dispose();
83 return 1;
84 break;
85 }
86
87 if (calcHandler(kind, arg1, arg3, &result) != 0)
88 {
89 fprintf(stderr, "Error: calcHandler failed\n");
90 console_dispose();
91 return 1;
92 }
93
94 printf("%d\n", result);
95
96 console_dispose();
97 return 0;
98}
int main(int argc, char *argv[])
プログラムのエントリーポイント。
Definition calc.c:43
計算ライブラリ (動的リンク用) のヘッダーファイル。
CALC_EXPORT int CALC_API calcHandler(const int kind, const int a, const int b, int *result)
指定された演算種別に基づいて計算を実行します。
Definition calcHandler.c:21
#define CALC_KIND_MULTIPLY
乗算の演算種別を表す定数。
#define CALC_KIND_SUBTRACT
減算の演算種別を表す定数。
#define CALC_KIND_DIVIDE
除算の演算種別を表す定数。
#define CALC_KIND_ADD
加算の演算種別を表す定数。