Write a .c file named calc that:
- Takes arguments from the command line
- Solves a simple math problem
- Returns the result as an exit status
calc.c:
//this is the function that gets called when the executable is run.
int main(int argc, char * argv[]){
//I've given you the next part for free.
//it gets the first three arguments from the command line.
//we'll discuss exactly how this happens in a later class.
//to be explicit imagine we wrote
// ./calc 1 0 2
int op1 = argv[1][0]-48; // this would be 1
int operation = argv[2][0]-48; // this would be 0
int op2 = argv[3][0]-48; // this would be 2
// START OF YOUR CODE
// fill out the main method to support
// 0 - addition
// 1 - subtraction
// 2 - multiplication
// 3 - division
//
// don't forget to return your result.
// you can view the result returned from your code by typing
// echo $?
// from the terminal (command line)
// END OF YOUR CODE
}
makefile:
first:
gcc -o calc calc.c