The purpose of this assignment is to introduce you to systems programming in C, which is the language that we will be using throughout the semester. You must complete this program in C, not C++ or C#. In particular, it must compile with gcc without any -std options. Your program must compile and run on your virtual machine (VM), although you may develop it on any machine you like, such as on the MultiLab.
You will be graded on exact adherence to these specifications.
prog1.c, and the executable program is called
prog1 FILEwhere FILE can be any valid Unix file name, such as
|q||Quit the program.|
|e||Print the name by which the program is called (argv)|
|p n||Print the first n bytes of FILE as characters.|
|L n||Print the last n bytes of FILE as characters.|
|i n||Print the first 4n bytes of FILE as n unsigned integers, separated by a space|
|x n||Print the XOR of the first n bytes of FILE as a 3-digit unsigned octal number.|
Makefilemust be able to compile your program when you run
make prog1You should start with the
Makefilethat you can get this way:
wget http://www.cs.uky.edu/~raphael/courses/CS270/project1/MakefileYou may modify this file.
gcc -Wall prog1.c -o prog1The
Makefilewe provide invokes the compiler exactly this way.
wget http://www.cs.uky.edu/~raphael/courses/CS270/project1/workingProgram chmod +x workingProgram
od -t u4 -t o1 FILE
The man program can tell you about useful programs and functions in the C
library. For example, run this program to find out about the
man 3 printfThe
3means "section 3 of the manual", which is where the C library is documented. You can leave off the "3" and find all references to
You might find the following functions useful:
open fopen read fread close fclose lseek fseek printf fprintf scanf fscanf sscanf strtok strspn fgets atoiIt is a good idea to write your entire program using open/read/close/scanf or using fopen/fread/fclose/fscanf; don't use some of the first series and some of the second series.
For programs, correctness is an important criterion, but is by no means the whole story. Here are some suggestions for programming in general.
Makefileand partially in
http://www.cs.uky.edu/~raphael/writing.htmlfor guidance. Run all code and documentation through a spelling checker such as ispell or aspell.
http://www.cs.uky.edu/~raphael/checklist.htmlfor suggestions on programming standards, and
http://www.cs.uky.edu/~raphael/programming.htmlfor techniques specific to C and basic information about Unix.
Makefile, and a
file. Do not
submit other files. To create your submission, tar and compress all files that
you are submitting. There is a recipe in the
Makefile that we provide:
README file must be a text file, not a file in MS Word,
PostScript, PDF, or any other non-text format.
README should include at least your name, a list of the files
you are submitting, a short description of the project, any known bugs, and a
short description of your testing.
Upload your submittal via
You can do so from a browser on your VM, or you can copy it to some other
machine and submit it with a browser from there.
You may upload it as many times as you like; we grade only the last submission.
Once we have graded a submission, we ignore later submissions.