-
Notifications
You must be signed in to change notification settings - Fork 0
/
cliuti.c
37 lines (32 loc) · 974 Bytes
/
cliuti.c
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
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
int main(int argc, char *argv[])
{
// You have to create a command line utility to add/subtract/divide/multiply two numbers
// First command line argument of your c program must be the operation.
// The next arguments being the two numbers. For example:
// >>Command.c add 45 4
// >>49
char * operation;
int num1, num2;
operation = argv[1];
num1 = atoi(argv[2]);
num2 = atoi(argv[3]);
// printf("Operation is %s\n", operation);
// printf("Num1 is %d\n", num1);
// printf("Num2 is %d\n", num2);
if(strcmp(operation, "add")==0){
printf("%d\n", num1 + num2);
}
else if(strcmp(operation, "subtract")==0){
printf("%d\n", num1 - num2);
}
else if(strcmp(operation, "multiply")==0){
printf("%d\n", num1 * num2);
}
else if(strcmp(operation, "divide")==0){
printf("%d\n", num1 / num2);
}
return 0;
}