You must work on this lab individually.
If you are actually enrolled
in CPE 101 (not waitlisted or added) you should have a
computer account that allows you to logon to most of the Computer
Science Department computers. If you are adding the class, we will need
to request an account for you using this form.
This lab helps you login, edit a file, and handin the file. The file you create will be handed in to me electronically in the same manner you will hand in all your labs and programs this quarter.
That being said, you can attempt to log
in following
these
instructions to log on to server named vogon. You
can do so in the Computer Science Lab (CSL) in 14-235 or
from any other computer
with an internet connection running UNIX, Linux, OS-X, or Windows.
Being able to do this from home will increase your level of success in
this class since it will enable you to work when and wherever you want.
If you are using Windows at home you will have to download and install
the SSH client described in the instructions linked above.
If you logged on to a
machine in the lab you are still not quite on vogon. You'll have to
start a terminal and connect to vogon using the command:
ssh vogon
Later, when you are done working on vogon,
you will leave the machine by typing:
exitPart 2: Create a new file using an editor
Once you are successfully logged on to vogon, you will need to create a file from the command line. You should see a prompt that will look something like this:
Now, enter the following command exactly as specified. I have made all of the commands that you are to enter in bold face.
i (command mode) |
switch to insert mode |
Esc (insert mode) |
switch to command mode |
j |
move down |
k |
move up |
h |
move left |
l |
move right |
x |
delete character |
:w |
save file |
:q |
exit vim |
This is my lab 1 file.
This class is CPE 101.
Copy the miles2feet.c and checkit.h files into your directory.
Note that the ~djanzen means in djanzen's home directory, and the . means in the current directory.
Type ls to confirm that two files are now in your directory.
Use vim to edit miles2feet.c. Add a variable miles, use printf and scanf to read a value into miles, then use the function to convert miles to feet and print the result.
Compile your program with the following command:You can simplify your compilation by using a makefile. First, download the sample makefile. Once you place this file in your lab directory, edit it so the compile command is the same as above. Then, you can compile your code just by typing:
vogon: ~$ makeNOTE: If editing the second line in the makefile (after the line default), you must insert a Tab character before the gcc command. You can do this in vi by entering Ctrl-V, and then entering the Tab key.
Part 5: Input/output redirectionIn this lab, you should also test your program with input and output redirection. Create an input file named sample_input. This file should contain one line with the input you want read by your program (e.g. 3). Input redirection allows you to send input from a file instead of reading it from the keyboard. You can test your program with the following command:
vogon: ~$ m2f < sample_inputYou will notice that when using input redirection, the input from the file will not be shown to the screen. To save the output of your program to a file, use output redirection:
vogon: ~$ m2f < sample_input > sample_outputThe previous command will read input from the file sample_input and save the output to a file name sample_output. You can look at the contents of program_output with the following command:
vogon: ~$ more sample_outputThe diff program compares 2 files and prints out any differences between the files. This is useful for comparing your program output with the expected output. For example, the command:
vogon: ~$ diff -w -B sample_output ref_outputIf the 2 files are exactly the same, diff will print out nothing to the screen. If the files are different, diff will print out the differences. For those interested, here is a how to read diff output. Make a small change to your sample_output file, then rename it to ref_output. Run your program again using the input/output redirection. Do a diff to see the differences in the two files.
When you are done, leave vogon by typing the following:
vogon: ~$ exitCommand |
Usage Example |
Description |
cd |
cd my_dir |
Change to my_directory |
more |
more testfile |
Look at the contents of testfile |
pwd |
pwd |
Show the present working
directory |
ls |
ls |
List the files in the current
directory |
mkdir |
mkdir test |
Make a new directory called
'test' |
rm |
rm testfile |
Delete the file named 'testfile' |
hostname |
hostname |
Show the name of the computer |
exit/logout |
exit |
End the current shell session |