Classwork 15: Command Line Arguments

Thursday, August 10, 2012     


[Previous Classwork] [Next Classwork]


Complete the following:

  1. Create a file named cw15.c
  2. Write a program that must take in 3 command line arguments.
  3. You must prompt the user with the correct number of arguments when an incorrect number is entered.
  4. Based on the first command line argument complete the following:
    • Add — Adds the next two command line arguments and prints the result
    • Sub — Subtracts the next two command line arguments and prints the result
    • Eq — Tests the next two command line arguments for equality and prints the result.
    • Cat — Concatenates the next two command line arguments and prints the result.
    Please remember, you may need to convert the command line arguments from Strings to other types. You will need to include the stdlib.h library.
  5. Here is a sample run based on the following:
    linux3[25]% ./cw15 Add 5 10
    Adding 5 + 10 = 15 Thank you for running our program.
    linux3[26]% ./cw15 Cat Big Foot
    Concatenating Cat & Foot - BigFoot Thank you for running our program.
  6. Once you are done, use submit
    linux3[26]% submit cs104 cw15 cw15.c typescript
    

  7. After submitting your files, you can verify your files were submitted by using the submitls command
  8. MAKE SURE YOU LOGOUT AFTER SUBMITTING THE ASSIGNMENT AND BEFORE LEAVING CLASS!