CS 101
Lab 6 Answer Sheet

This lab is to be worked individually.

Name: ________________________ Netid: _______________ Section: _______


Part 1: Prelab


Part A: Basic UNIX commands


1. Let's say you are currently in your home directory (directory named after your netid. you can type 'cd ~/' and hit enter to move to your home). Write a UNIX command to list all the files and directories in your working directory.


___________________________________________________________

2. Now suppose you also want to know the size of all the files in your working directory. Write a UNIX command that will list all files in your working directory listing the size of the files.


___________________________________________________________

3. In general, a simple list command will not display the files and folders whose names start with a dot. You can, however, tell 'ls' to display these hidden files. Write a UNIX command to list all the files and directories in your home directory, including the files whose names begin with a '.' (a dot).

___________________________________________________________

4. Still in your home directory, write the UNIX command to create a new subdirectory called prelab6 that is inside your home directory.


___________________________________________________________

5. Now, assuming that you are still in your home directory and you have a file there named prelab6.c, write a UNIX command to rename this file to the pre6.c

___________________________________________________________

6. Write a command to make another copy of this file pre6.c to the new subdirectory named prelab6. 

___________________________________________________________

7. Write a command to copy the entire prelab6 directory to a directory called prelab6_copy in your home directory.

___________________________________________________________

8. Still in your home directory you decide to delete the pre6.c file from your home directory. Write the UNIX command to remove the file from its directory.

___________________________________________________________

9.    Oops! We didn't want to delete that file! Luckily we have another copy of the file. From your home directory,  copy the file pre6.c, which is in your prelab6 directory, to the home directory with a new name p6.c. Write the UNIX command to copy this file to your current directory with the new name. Do not use the cd command to change back to your home directory.

_____________________________________________________________

10. We were luck we had a copy of pre6.c when we "accidentally" removed it, however, UNIX does not have a recycle bin, so we should be careful when removing files, specially when we use the -r flag to remove everything (including sub-directories) from a directory. Write an UNIX command that uses the -i flag to remove the prelab6_copy folder while resquesting confirmation before removing each file or folder.


___________________________________________________________

11. Still in your home directory, write a UNIX command to list all the C files that begin with letter 'p' (C files end with '.c').


___________________________________________________________

12. Use the cd command to change to the prelab6 directory. Without using the cd command again to change back to your home directory, write the UNIX command to list the contents of your home directory.

___________________________________________________________



Part B: C Programming Language

13. Fill in the blanks below with the most appropriate datatype to declare each of the variables below.

___________ studentNo; /* the number of students in a class */


___________ avgScore; /* the average score of a class in CS101 midterm (a high precision real number) */


___________ gender; /* single character indicating the gender of a student, either a 'M' or an 'F' */

14. Fill in the following blank with the correct conversion specifier:

printf( "y = _____ ", _____ );

Fill in the following blank with the correct conversion specifier:

printf("UIN:____, Gender:____", _____, ____);

15.
int a = 11;
int b = 4;

a % b = __________________________

(a+1)%b = _______________________

a/b = ___________________________

16. Fill in the blank to read a single character value into the variable s and a single double value into variable t declared below.

char s;
double t;
scanf( "%c" , __________);
scanf("____________", __________);


Part 2: Navigating the filesystem with the command prompt


1. Write the commands to navigate to your home directory from the root directory:





2. Write the error message(s) that gcc shows:








3. Write what happens when you run your program for the first time after it compiles:






4. Write the output your corrected program now produces: ___________________________________________________________



5. Change the line of code

 if (x % 2)
so that we are testing for x being a multiple of three rather than two .


Write the new line of code: _________________________________________________________________________________