Remember to create a new directory in your repository for this lab. (Refer to previous labs for how if you have forgotten)
You have two tasks to complete before your lab. First, refer to your notes about strings, , command-line arguments, pointers, and structs, and answer the questions in lab4questions.html.
Second, read through the warmup exercises so you are ready to begin in class.Up until now, your program has executed all of the tests in a single run. This is fine when all goes well. However, if one of your tests experiences a segmentation fault, then the program ends, and further tests will not execute. This is not ideal.
Instead, each test should be a separate execution of the program. Then, you string together the tests with a script. This script contains the command line for each test. If one fails, that's fine, it then proceeds to the next test. Therefore, you need a file you didn't need before: the script.
The command-line arguments provide all information to know which test to execute and provide any input arguments it needs. If you missed the lecture on command-line arguments, you can read an on-line tutorial.
For example, let's take the exercises you are going to be completing for the
string warm-up. We can assign a letter to each one of them, shown below:
0) Count the number of vowels in the string
1) Convert the string to lowercase and print out resulting string
2) Create and initialize a heightxwidth image, write to filename.
To use this program, you would do the following:
This would result in:./warmup4 0 16 THE QUICK BROWN FOX JUMPED. THE LAZY DOG, HE WAS JUMPED OVER.
Likewise,16 - PASSED
This would result in:./warmup4 1 THE QUICK BROWN FOX JUMPED. THE LAZY DOG, HE WAS JUMPED OVER.
Likewise,the quick brown fox jumped. the lazy dog, he was jumped over.
would create an image that is 200x500, with each pixel being (128, 0, 128)../warmup4 2 200 500 128 0 128 test200x500rb.png
Once you have made testscript, you need to make it executable: chmod +x testscript../warmup4 0 16 THE QUICK BROWN FOX JUMPED. THE LAZY DOG, HE WAS JUMPED OVER. echo "Expected: the quick brown fox jumped. the lazy dog, he was jumped over." ./warmup4 1 THE QUICK BROWN FOX JUMPED. THE LAZY DOG, HE WAS JUMPED OVER. ./warmup4 2 100 50 0 128 128 test100x50gb.png ./warmup4 2 200 500 128 0 128 test200x500rb.png
During the warmup, you are going to implement several functions that exercise strings, pointers, and structs.
Create the skeleton code. This is NOT given to you. You need to fill it in.
warmup4.h,
warmup4.c,
warmup4_main.c, and
testscript.
Count the number of vowels (a,e,i,o,u) in the string. str is an in parameter. You may NOT use any library calls within count_vowels.
Modify the string so that all capital letters ('A'-'Z') are changed to their corresponding lower-case letters. str is both an in parameter and an out parameter. You may NOT use any library calls within make_lowercase.
typedef struct { unsigned int red; unsigned int green; unsigned int blue; } pixel; pixel** make_and_init_image(int height, int width, pixel color);
Write a function that creates a double array of pixels. It consists of an array of length height, and each element of that array points to an array of length width. The array of length width is an array of pixels. Each pixel is initialized to color. Make sure you put the struct definition in the .h file ONLY - not also the .c file.
I have now provided the png files to go along with this assignment. You can use warmup4_provided.h, warmup4_provided.c, uchicago.png
If you inspect these files, you will see that we have provided the read and write to png files. For this exercise, you need only the write function. This represents two changes. First, it uses the pixel data structure. Second, it uses malloc, removing the restrictively small size limitation. You can now use it on much larger pictures.
One note: The pixel struct is declared in warmup4_provided.h. This means you do NOT need to place it in your own warmup4.h file. You cannot put it twice. That means you need to #include the warmup4_provided.h file before the warmup4.h file.