CS 204 Lab 2
CS 204 Lab 2
This is the first part of a three-part lab that aims to build a bench
calculator, that is a program that computes the value of simple
expressions on the command line. No work needs to be submitted this
week, but it is important that you do the work, because you will need
it next week.
To get you started, here is some code for creating a new empty stack:
If your program is in a file calc.c, then you compile your program using
gcc:
gcc -o calc calc.c
Or you can use the clang compiler:
clang -o calc calc.c
Once you have compiled your program, you can run it with:
./calc
If you don't have a main function in your program, the compiler
will complain that it can't find a main function.
The following is some simple example code that reads in command line
parameters.
if ( argc == 1 ) {
printf("Please try adding some command-line parameters\n");
printf("Usage: %s <param1> <param2> ...\n", argv[0]);
exit(1);
}
return 0;
}
// end of code
To run your program with command line parameters, you will write something
like:
./calc 45 27 13.2 8