Due: Wednesday, January 31 2007, 6:00pm
You will get experience writing short C programs and manipulating strings and arrays in C.
In addition to the lecture notes, you may find "Programming in C" a useful reference for completing this assignment.
Download the file: hw3.tar.gz.
Extract all the files for this assignment using the following command:
> tar zxvf hw3.tar.gz
You should now see a directory called hw3.
If you see it, you are ready to start the assignment. If this procedure did not work for you, please contact a TA or talk to another student in the class.
Every time you learn a new language, the first thing you need to try is to write the simplest program possible.
In a file called my_test.c, write a C program that prints the string "Success!" and exits.
In a file called my_test2.c, write a C program that takes two integers as command line arguments and outputs their sum. This program does not have to perform any error-checking, except to check that the correct number of arguments is provided. If the user provides fewer than 2 arguments on the command line, your program should print an error message and should exit with exit status 1.
Hint: To convert a string to an integer, one possibility is to use the atoi function. To learn more about this function try man atoi or use your book.
In a file called problem2.c, write a C program that prompts the user
for a floating point number and prints the following:
Requirement: The results should appear on two distinct lines and should look right-aligned with respect to each other.
Please enter a floating point number: > 45.6
Examine the file problem3.c. It contains three functions in addition to main. Each function corresponds to one question. Each question asks you to either complete or explain the code.
Please complete problem3.c by adding the missing code and answering the questions directly in the file.
To answer a question, uncomment the call to the corresponding function in main. Compile and execute the program problem3.c. Examine the output produced.
In a file called problem4.c, write a C program that takes a list of N integers as command line arguments and performs the following operations:
Requirement: You program must be composed of at least five functions.
Requirement 2: All functions should be preceded by a comment block of the following form. For each parameter, indicate in the description whether it is modified by the function or not.
* Brief description of the function
* @param name_of_first_param description of first param
* @param name_of_second_param description of second param
* @return description of what value is returned
Your friend Bob is just learning about strings in C. He is having a lot of trouble. He wrote a few functions in a file called problem5.c, but some of them have bugs and some of them are not complete. Can you help him finish his work?
Note: this problem is not especially hard. If you have time to do it, you should try. It will give you additional practice working with strings.
In a file called problem6.c, write a C program that takes a list of N strings as input (on the command line) and performs the following actions:
Here's a sample output:
./problem6 boston laptop yesterday geese sweden book
|String: eeg||Size: 3|
|String: ey||Size: 2|
|String: koob||Size: 4|
|String: ob||Size: 2|
|String: potpal||Size: 6|
Requirement2: Make sure to comment all the functions that you write, using the same style of comments as in the previous question.
You should work on this assignment in a group of two. Each group should turn-in only one copy of the solution. Please make sure to write both names inside each file that you hand in.
Here is the list of files that you need to turn in:
Please find the detailed turn-in instructions here.