CISC106 Fall 2006 Lab06
CISC106 Fall 2006 Lab06
- Write a program or webpage for each of the following problems. Be sure to
save every separate program. All programs must be properly commented
and indented (see Assignment Standards on the class website).
- Work on the webpage during lab. It should go very quickly and
you will want your TA there in case you have a question. You may
work with other students if you have trouble getting your webpage to
appear, but as usual, all your other programming must be done by yourself.
- Name each program lab06.n.c, where n is the number in the list
below. For example, the name of the file for the first will be
lab06.1.c. Put the files in your lab06 directory.
Programs
- See makeWebpage.html for the first part of this lab. Look up the chmod command from part 1 in your Anderson. Can't find it?
Look for "mode" in the index. Explain what a+rx means, in a text file or on your script.
-
Copy lab03.3 into this lab directory and rename it
appropriately. Compile it using the "-o" option so that the
executable file is named "threes" instead of "a.out". Test to see
that it still works.
Place the multiples generated by your program
into a data file called
threes.txt. To do this, use the Unix redirection operator > like
this:
threes > threes.txt
Now you will read them into two separate arrays. Make two integer
arrays of size 25. Start a loop reading the elements from the data
file. As each element is read, print it out.
Next, still inside the read loop, use mod so that elements numbered 0, 2, 4 etc. go into the first
array, while elements numbered 1, 3, 5 etc go into the second array
(Looking at the data, what would be good names for the arrays?).
After all the data is read, print the arrays separately.
- Modify the previous problem so that it writes the output to a
file. Use fopen in "w" mode, fprintf and a loop to write the
whole array to a new file output.txt. Then rename that file to
~/public_html/cisc105/lab06output.txt
Use chmod to make it readable so your TA (and the world) can see
it.
- A character is
represented by putting a symbol inside single quotes, so 'a'
is of type char. Use characters in quotes the same way you would use
an integer value, i.e. you can say
char c = 's';
Write a program with a char variable. Ask the user to type a
char, read it into your variable as a single char, and print "Not a Q" or "That's a Q" depending
on the input.
-
Write a program that reads a single char and loops as long as the user enters a 'q'. Inside
the loop, print the character (using the format specifier %c)
that the user entered. What odd
behavior do you observe? Note this in your comments and say how you
addressed it.
You should have a total of 5 programs named lab06.1.c to
lab06.5.c. Make a single script file (see lab00 for the
instructions) where you cat, compile, and run each one in its final form.
Submit all C files and your script on WebCT, and give the paper version of the
complete script file only to your TA
at the beginning of your next lab (all Friday labs) or in lecture Friday
(Wednesday labs only). Note: Cat, compile, and run each
program in order! Do not cat all programs, then compile, etc.
File translated from
TEX
by
TTH,
version 3.38.
On 11 Oct 2006, 07:30.