The main purpose of this lab is to get you ready to do stage 6 of project 1. Stage 6 is worth 10% of project 1. This lab also has a small required component: it teaches you how to work with HTML files, and how to write data to an external file in C.
By the time you finish this lab, you should be able to do all of the following:
html, head, body, title, h1, p, table, tr, th, td.fprintf(stderr,"...") instead of printf("...");argv[1])argc.__FILE__
<html>
<head>
<title>Joe Sample's CISC105 Web page</title>
</head>
<body>
<h1>Joe Sample's CISC105 Web page</h1>
<p>I had to do this <b>web page</b> for my
<a href="http://udel.edu/~pconrad/cisc105"> CISC105 class</a>.
</p>
|
Here's what that looks like once it is formatted by a web browser:
Joe Sample's CISC105 Web pageI had to do this web page for my CISC105 class. |
<html>
<head>
<title>Joe Sample's CISC105 Web page</title>
</head>
<body>
<h1>Joe Sample's CISC105 Web page</h1>
<p>I had to do this <b>web page</b> for my
<a href="http://udel.edu/~pconrad/cisc105"> CISC105 class</a>.
</p>
<table border="10" cellspacing="2">
<tr>
<th>pizza topping</th>
<th>number of pizzas</th>
<th>salad dressing</th>
<th>price of pizza (dollars)</th>
</tr>
<tr>
<td>green peppers</td>
<td>5</td>
<td>blue cheese</td>
<td>$ 5.99</td>
</tr>
</table>
|
Here's what THAT looks like when formatted by a web browser:
Joe Sample's CISC105 Web pageI had to do this web page for my CISC105 class.
|
When you are finished, make sure that the page is readable on the web.
Just like Part 1 of last week's lab, this part of the lab does not involve anything that you have to turn in for credit. So, you could skip it, and neither your instructor nor your TA would have any way to know.
But you really ought to do it anyway. If you don't, you won't have the information you need to proceed. These example files are there to be your "teachers".
To get started, log on to strauss and do the following commands.
Note that in the last command, after the star, there is a space, then a period. That star, that space and that period are really important. The command tells strauss to "copy all the the files from a certain directory on pconrad's web site into my current directory". The period (by itself) means current directory. If you leave it off, you'll get an error message—possibly something about "permission denied" or "target not a directory" or some such thing.
cd ~/cisc105
mkdir lab03
cd lab03
mkdir htmlBuilders
cd htmlBuilders
cp ~pconrad/public_html/cisc105/05F/work/labs/lab03/htmlBuilders/* .
After doing these commands, if you do an ls command to list your files, you'll see something like the following:
> ls
Makefile htmlBuilder1.c htmlBuilder2.c htmlBuilder3.c test.html
>
You can also see these files at the following web link
In this directory, you see lots of .c files, and also a special file called Makefile. Use "cat" or "more" to take a look inside that file for a moment:
cat Makefile
more Makefile
You'll see some comments in the file that tell you a little bit about it. However, all you really need to know about it for now is that it enables you to compile a whole bunch of programs with a single command:
make
Try typing that command. You should see something like the following:
> make
gcc -o htmlBuilder1 htmlBuilder1.c The system compiles each one of the .c programs and puts the executable code (the stuff that normally goes into a.out) into a separate file for each program, just like last week. .
gcc -o htmlBuilder2 htmlBuilder2.c
gcc -o htmlBuilder3 htmlBuilder3.c
>
Just like last week, you can change which compiler is used by changing the line in the Makefile that says CC=gcc to CC=cc (note the capital and small letters).
You can now run any of these programs by typing a dot and a slash, followed by the name of the program. For example, to run the program that corresponds to htmlBuilder1.c, type:
./htmlBuilder1
and to run the program that corresponds to htmlBuilder2.c, you type:
./htmlBuilder2
Try running ./htmlBuilder1. It will probably appear as if nothing happened.
> ./htmlBuilder1
>
However, if you now do an ls command to list your files, you'll see that there is a new file in your directory that wasn't there before:
> ls
Makefile htmlBuilder1.c htmlBuilder2.c htmlBuilder3.c
htmlBuilder1 htmlBuilder2 htmlBuilder3 test.html
>
Note the new file test.html. Try deleting that file, doing an ls, then running the program htmlBuilder1 again, and doing the ls again, as shown here:
> ls
Makefile htmlBuilder1.c htmlBuilder2.c htmlBuilder3.c
htmlBuilder1 htmlBuilder2 htmlBuilder3 test.html
> rm test.html
rm: remove test.html (yes/no)? yes
> ls
Makefile htmlBuilder1 htmlBuilder1.c htmlBuilder2 htmlBuilder2.c htmlBuilder3 htmlBuilder3.c
> ./htmlBuilder1
> ls
Makefile htmlBuilder1.c htmlBuilder2.c htmlBuilder3.c
htmlBuilder1 htmlBuilder2 htmlBuilder3 test.html
>
Note that the test.html file comes back.
If you look at the source code for this program (htmlBuilder1.c) you can learn all kinds of useful things. Find all the places where the program:
FILE * variable called htmlFile to be a "pointer to a file" fopen()to associate the pointer htmlFile with the file test.htmlfprintf(stderr,"...") and perror("...") to write out error messages if the file cannot be openedexit(1); to indicate that an error occured and end the program if an error happens fprintf(htmlFile,"..."); to write HTML tags and text into the file. (fprintf() works just like printf(), except it has one extra parameter at the beginning; a FILE * variable that points to where the data should be written) \" to put a quotation mark in the middle of a string that is being written out, for example: "<a href=\"http://www.udel.edu\">UD's home page</a>". (Otherwise the " symbol would prematurely end the string!) fclose(htmlFile); to close the file when we are finished writing to it. This program always writes a file called "test.html", and what is written to the file is always that same. That is kind of boring. So in htmlBuilder2 I've added code so that the name of the file can be specified on the command line. Look for the following changes in htmlBuilder2.c:
.
Your job is to look through all three programs, and understand how they work. You'll need this understanding in order to complete stage 6 of project 1, which is due in two weeks, and is worth 10% of the project, and therefore 1% of your final course grade. So, I hope you will accept this mission!
Your instructor will go over these programs with you in lecture over the coming days, but you can learn quite a bit about them on your own just by reading the code, running the code, and by experimenting. Don't be afraid to make your own copies of these programs and try adding your own variables and your fprintf() function calls. That is the one the best things you can do to become a more skillful programmer works.
When you are all done, you can type the following command:
make clean
This will get rid of all the executable files. This is good, because they take up a lot of disk space, and you don't need to keep them around unless you are actively working with the programs in this directory. You can bring them back anytime you like by typing make again, so why keep around the executables?
In this part of the lab, you are going to do stage 6 of project 1. This is NOT REQUIRED for lab03; it is a part of project 1 that is described here for convenience sake.
First finish up project 1 up thorugh stage 5. Then, cd into your ~/cisc105/proj1 directory (this is where you should be working, NOT ~/public_html/cisc105/proj1), and copy your proj1s5.c file to proj1s6.c.
Then, following the example of htmlBuilder3.c, add code into your program so that after you prompt the user for values and echo those values back to the user, you create an html file that has a table of those values in it.
Take the name of the html file from the command line, following the example of htmlBuilder3.c.
When you script project 1 (if you include stage 6), you should run the program at least twice, specifying different filenames for the generated html file, and different values (e.g. two different skyscrapers, two different movies directed by Steven Speilberg, two different female tennis stars.)
The two filenames should reflect the content, e.g.
You should then copy the generated files to ~/public_html/cisc105/proj1, and make them readable. When the TA looks at your script, he'll also access your web page to make sure that the files there match the ones in your script.
To submit lab03, you need to do each of the following:
NOTE AGAIN: stage 6 of project 1 is due as part of project 1; it is not part of lab03.
Total points for lab03: 25 points.