-
Notifications
You must be signed in to change notification settings - Fork 4
/
handler.cpp
328 lines (304 loc) · 7.43 KB
/
handler.cpp
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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
#include <stdio.h>
#include <math.h>
#include <stdlib.h>
#include <string.h>
#include "util.h"
void acos_handler(void)
{
double x = getDouble("x = ");
printf("acos(%f) => %f\n", x, acos(x));
}
void fabs_handler(void)
{
double x = getDouble("x = ");
printf("fabs(%lf) => %lf\n", x, fabs(x));
}
void asin_handler(void)
{
double x = getDouble("x = ");
printf("asin(%lf) => %lf\n", x, asin(x));
}
void atan_handler(void)
{
double x = getDouble("x = ");
printf("atan(%lf) => %lf\n", x, atan(x));
}
void atan2_handler(void)
{
double x = getDouble("x = "), y = getDouble("y = ");
printf("atan2(%lf, %lf) => %lf\n", y, x, atan2(y, x));
}
void cos_handler(void)
{
double x = getDouble("x = ");
printf("cos(%f) => %f\n", x, cos(x));
}
void sin_handler(void)
{
double x = getDouble("x = ");
printf("sin(%f) => %f\n", x, sin(x));
}
void tan_handler(void)
{
double x = getDouble("x = ");
printf("tan(%f) => %f\n", x, tan(x));
}
void cosh_handler(void)
{
double x = getDouble("x = ");
printf("cosh(%f) => %f\n", x, cosh(x));
}
void sinh_handler(void)
{
double x = getDouble("x = ");
printf("tan(%f) => %f\n", x, sinh(x));
}
void tanh_handler(void)
{
double x = getDouble("x = ");
printf("tan(%f) => %f\n", x, tanh(x));
}
void ceil_handler(void)
{
double x = getDouble("x = ");
printf("ceil(%lf) => %lf\n", x, ceil(x));
}
void floor_handler(void)
{
double x = getDouble("x = ");
printf("floor(%lf) => %lf\n", x, floor(x));
}
void exp_handler(void)
{
double x = getDouble("x = ");
printf("exp(%lf) => %lf\n", x, exp(x));
}
void fmod_handler(void)
{
double x = getDouble("x = "), y = getDouble("y = ");
printf("fmod(%lf, %lf) => %lf\n", x, y, fmod(x, y));
}
void frexp_handler(void)
{
double x = getDouble("x = "), y = 0.0;
int exp;
y = frexp(x, &exp);
printf("%lf = %lf * 2 ^ %d\n", x, y, exp);
}
void ldexp_handler(void)
{
double x = getDouble("x = ");
int exp = getInt("exp = ");
printf("ldexp(%lf, %d) => %lf\n", x, exp, ldexp(x, exp));
}
void log_handler(void)
{
double x = getDouble("x = ");
printf("log(%lf) => %lf\n", x, log(x));
}
void log10_handler(void)
{
double x = getDouble("x = ");
printf("log10(%lf) => %lf\n", x, log10(x));
}
void modf_handler(void)
{
double x = getDouble("x = "), y = 0.0, i = 0.0;
y = modf(x, &i);
printf("%lf = %lf + %lf\n", x, i, y);
}
void pow_handler(void)
{
double x = getDouble("x = "), exp = getDouble("exp = ");
printf("%lf ^ %lf = %lf\n", x, exp, pow(x, exp));
}
void sqrt_handler(void)
{
double x = getDouble("x = ");
printf("sqrt(%lf) = %lf\n", x, sqrt(x));
}
/////////////////////////////////////////////////////
//////////////string_handler////////////////////////
////////////////////////////////////////////////////////
void memchr_handler(void)
{
char *s = getString("s = ");
char c = getChar("c = ");
size_t n = getSize_t("n = ");
printf("memchr(%s, %c, %lu) = %s\n", s, c, n, memchr(s, c, n));
}
void memcmp_handler(void)
{
char *s1 = getString("s1 = ");
char *s2 = getString("s2 = ");
size_t n = getSize_t("n = ");
printf("memcmp(%s, %s, %lu) = %d\n", s1, s2, n, memcmp(s1, s2, n));
}
void memcpy_handler(void)
{
char *s1 = getString("s1 = ");
char *s2 = getString("s2 = ");
size_t n = getSize_t("n = ");
printf("memcpy(%s, %s, %lu) = %s\n", s1, s2, n, memcpy(s1, s2, n));
}
void memmove_handler(void)
{
char *s1 = getString("s1 = ");
char *s2 = getString("s2 = ");
size_t n = getSize_t("n = ");
printf("memmove(%s, %s, %lu) = %s\n", s1, s2, n, memmove(s1, s2, n));
}
void memset_handler(void)
{
char *s = getString("s = ");
char c = getChar("c = ");
size_t n = getSize_t("n = ");
printf("memset(%s, %c, %lu) = %s\n", s, c, n, memset(s, c, n));
}
void strcat_handler(void)
{
char *s1 = getString("s1 = ");
char *s2 = getString("s2 = ");
printf("strcat(%s, %s) = %s\n", s1, s2, strcat(s1, s2));
}
void strchr_handler(void)
{
char *s = getString("s = ");
char c = getChar("c = ");
printf("strchr(%s, %c) = %s\n", s, c, strchr(s, c));
}
void strcmp_handler(void)
{
char *s1 = getString("s1 = ");
char *s2 = getString("s2 = ");
printf("strcmp(%s, %s) = %d\n", s1, s2, strcmp(s1, s2));
}
void strcoll_handler(void)
{
char *s1 = getString("s1 = ");
char *s2 = getString("s2 = ");
printf("strcoll(%s, %s) = %d\n", s1, s2, strcoll(s1, s2));
}
void strcpy_handler(void)
{
char *s1 = getString("s1 = ");
char *s2 = getString("s2 = ");
printf("strcpy(%s, %s) = %s\n", s1, s2, strcpy(s1, s2));
}
void strcspn_handler(void)
{
char *s1 = getString("s1 = ");
char *s2 = getString("s2 = ");
printf("strcspn(%s, %s) = %lu\n", s1, s2, strcspn(s1, s2));
}
void strerror_handler(void)
{
char errcode = getChar("c = ");
printf("strerror(%c) = %s\n", errcode, strerror(errcode));
}
void strlen_handler(void)
{
char *s = getString("s = ");
printf("strlen(%s) = %lu\n", s, strlen(s));
}
void strncat_handler(void)
{
char *s1 = getString("s1 = ");
char *s2 = getString("s2 = ");
size_t n = getSize_t("n = ");
printf("strncat(%s, %s, %lu) = %s\n", s1, s2, n, strncat(s1, s2, n));
}
void strncmp_handler(void)
{
char *s1 = getString("s1 = ");
char *s2 = getString("s2 = ");
size_t n = getSize_t("n = ");
printf("strncmp(%s, %s, %lu) = %lu\n", s1, s2, n, strncmp(s1, s2, n));
}
void strncpy_handler(void)
{
char *s1 = getString("s1 = ");
char *s2 = getString("s2 = ");
size_t n = getSize_t("n = ");
printf("strncpy(%s, %s, %lu) = %s\n", s1, s2, n, strncpy(s1, s2, n));
}
void strpbrk_handler(void)
{
char *s1 = getString("s1 = ");
char *s2 = getString("s2 = ");
printf("strpbrk(%s, %s) = %s\n", s1, s2, strpbrk(s1, s2));
}
void strrchr_handler(void)
{
char *s = getString("s = ");
char c = getChar("c = ");
printf("strrchr(%s, %c) = %s\n", s, c, strrchr(s, c));
}
void strspn_handler(void)
{
char *s1 = getString("s2 = ");
char *s2 = getString("s2 = ");
printf("strspn(%s, %s) = %lu\n", s1, s2, strspn(s1, s2));
}
void strstr_handler(void)
{
char *s1 = getString("s1 = ");
char *s2 = getString("s2 = ");
printf("strstr(%s, %s) = %s\n", s1, s2, strstr(s1, s2));
}
void strtok_handler(void)
{
char *s1 = getString("s1 = ");
char *s2 = getString("s2 = ");
printf("strtok(%s, %s) = %s\n", s1, s2, strtok(s1, s2));
}
void strxfrm_handler(void)
{
char *s1 = getString("s1 = ");
char *s2 = getString("s2 = ");
size_t n = getSize_t("n = ");
printf("strxfrm(%s, %s, %lu) = %lu\n", s1, s2, n, strxfrm(s1, s2, n));
}
/////////////////////////////////////////////////////
//////////////stdlib_handler////////////////////////
////////////////////////////////////////////////////////
void abs_handler(void)
{
int x=getInt("x=");
printf("abs(%d)=>%d\n",x,abs(x));
}
void atof_handler(void)
{
const char *s=getString("s=");
printf("atof(%s)=%lf\n",s,atof(s));
}
void atoi_handler(void)
{
const char *s=getString("s=");
printf("atoi(%s)=%d",s,atoi(s));
}
void bsearch_handler(void)
{
printf("Sorry!暂时不能实现\n");
}
void div_handler(void)
{
int number=getInt("number=");
int denom=getInt("denome=");
printf("div(%d,%d)=%d\n",number,denom,div(number,denom));
}
void getenv_handler(void)
{
const char *name=getString("name=");
printf("getenv(%s)=%s\n",name,getenv(name));
}
void qsort_handler(void)
{
printf("SORRY!该函数暂时无法实现\n");
}
void rand_handler(void)
{
int a;
printf("rand(void)=%d\n",rand());
}