Machine Problem 0 - Introduction to System Programming
- Due Date: 11:59 PM, Oct. 2, 2018
- Late submission: We don’t accept late submission in this homework.
In this homework, you will practice Linux programming and uploading your homework to GitHub.
Prerequisite
Join GitHub
Programming on the Workstation
If you don’t have a CSIE workstation account, refer to this page to apply an account.
Description
In this homework, you are required to write a simple C/C++ program and a Makefile, and push your code to your repository on GitHub. TA will only receive your code after you push them to the remote repository.
Work on your repository
Your GitHub repository page is located at https://github.com/SystemProgrammingatNTU/SP18-<StudentID>/
. Notify TA if anything goes wrong.
If it’s the first time you download the repo, run git clone
and your repo SP18-<StudentID>
will be created.
git clone https://github.com/SystemProgrammingatNTU/SP18-<StudentID>.git
cd SP18-<StudentID>
and repeat the modify-add-commit cycle to update your code until your job is done.
(create files, delete stuffs, update your code, etc)
...
git add file.a some.b bla.c
git commit -m 'The job description'
Run git push
to upload your code to the remote repository.
git push
You may google git tutorial
or git 教學
keywords to understand Git in depth.
File Hierarchy
Make a directory named MP0 in your repository. The MP0 dir contains the Makefile and source files.
repo
└── MP0
├── Makefile
└── other files
Makefile
We’ll compile your code with make
command. Write a Makefile that compiles the source code into an executable file char_count
under the same directory.
Program Usage
./char_count CHARSET [INPUT_FILE]
-
CHARSET
A set of printable characters and spaces. Characters are guaranteed to be unique.
-
INPUT_FILE
It’s an optional filename. Your program reads from it if specified. Otherwise your program reads from standard input. In the case INPUT_FILE does not exist, your program should print “error\n” to standard error and exit normally.
The input consists of printable characters, spaces, and ‘\n’. Your job is to count the occurences of characters in CHARSET for each line, and print the number of occurences respectively.
For example, suppose the CHARSET is “xyz” and your program encounters a line “yep.tar.xz\n”, it should output “3\n” (‘\n’ is new line character). Other examples are listed in example page. Implementation details can be found in Q&A page.
Time Limit
- Small input (<= 100MB) in 10 seconds
- Large input (~ 1GB) in 80 seconds
Notes
- Every line is guaranteed to have trailing ‘\n’ in input.
- INPUT_FILE is guaranteed to be a regular file or a non-existing path.
- CHARSET can be empty.
- The matching is case-sensitive.
- The input can be arbitrarily large and lines can be arbitrarily long.
Example
Submit your homework to GitHub
TAs regularly check the form and create your repository on GitHub. Your repo page should be on https://github.com/SystemProgrammingatNTU/SP18-<StudentID>
. Notify TAs if anything goes wrong.
Make sure you git push
to upload your code. The commit with last modification under MP0 directory (on master branch) is judged. The commits with commit date exceeding the due date are ignored.
Gradings
10 points in total. You get the points if anyone of these is completed.
- (2 pts) Create Makefile and
make
compiles thechar_count
binary without error. - (3 pts)
char_count
calculates the counts correctly and ends without error. - (2 pts)
char_count
can print “error\n” to standard error with questionable INPUT_FILE. - (3 pts)
char_count
can handle extra large input (at least 1 GiB). - (1 pt) Early bird point. You will get this point if you upload your code before Sep. 25 and don’t get all points.
Be aware that the commit with last modification under MP0 directory (on master branch) is judged. Plagiarism is prohibited, or you may receive F in this course.
Supplementary Materials
-
Manpages
man fprintf
shows the manual forfprintf
function in C standard library,man ls
shows the manual forls
shell command, etc. - Git
- Vim
- Makefile
- C