-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.cpp
More file actions
42 lines (36 loc) · 1.17 KB
/
main.cpp
File metadata and controls
42 lines (36 loc) · 1.17 KB
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
#include <cstdio>
#include <cstring>
#include <string>
extern "C" char* add(char* first_number, char* second_number);
extern "C" char* sub(char* first_number, char* second_number);
extern "C" char* multiplication(char* first_number, char* second_number);
int main(int argc, char **argv)
{
std::string operation = argv[1];
std::string fn = (char*)argv[2];
std::string sn = (char*)argv[3];
char *first_number = new char[fn.length() + 1];
std::strcpy(first_number, fn.c_str());
std::strcat(first_number, "\n");
char *second_number = new char[sn.length() + 1];
std::strcpy(second_number, sn.c_str());
std::strcat(second_number, "\n");
if (operation == "a") {
char* add_result = add(first_number, second_number);
printf("ADD: %s\n", add_result);
} else if (operation == "s") {
char* sub_result = sub(first_number, second_number);
printf("SUB: %s\n", sub_result);
} else if (operation == "m") {
char* multiplication_result = multiplication(first_number, second_number);
printf("MULTI: %s\n", multiplication_result);
} else {
delete first_number;
delete second_number;
puts("No operation");
return 1;
}
delete first_number;
delete second_number;
return 0;
}