To start getting used to programming in C, read Chapter 1 of K & R through section 1.6 (you may also want to take a look at the first few sections of chapter 5) and do the following practice program. You may work on it individually or in groups of two. If you have questions about how to compile a C program from the Unix/Linux command line, this document may help.
Clone the ParseInput Project: As with HelloWorld, this is an empty repository, but you need to create it so that you can submit your program when you're done.
ParseInput: Write a program that
repeatedly reads a line of text from stdin
into
an input buffer (array of type char
).
(fgets
is a standard library function to get a
string from a file, or, in this case, from the
keyboard.)
The input that the user types at the keyboard, should include some 0's
and 1's in it, along with other characters.
For each line, your program should report to the user:
'0'
characters there are
in this line, and'1'
characters there are
in this line.
The
set of C sample programs
contains three short programs at the end that provide examples of reading
into an input buffer, removing the newline at the end, and processing the
input. You may want to copy all three to your computer and compile and
run them to see what they do.
The first program will show you the ASCII code for every character in the
line, in both decimal and octal format.
The second and third programs read multiple lines in a loop; the second
counts numeric characters in the range of '0' - '9', while
the third contains an example of reporting the line number.
(You can download, compile, and test them in your repository
directory, but don't add them to the repository with git add
.
Only add your own program.)
As specified in the syllabus, your program should adhere to the Kalamazoo College CS Program Style Guide and Documentation Standards (unlike the sample programs), including use of the Braces Line Up style pattern.
Submit the Project:
Add your source file
to the Git "staging area", commit your changes (don't forget to include the
description, i.e.,
git commit -m "Short message"
), and push your changes.
Remember that you can complete the edit/add/commit/push cycle repeatedly. In fact, pushing versions of your project while it is still under construction is a way to create backups of your work as you go.
"Turn In" the Project: When you're done, click on the Turn In button in Kit to signal that your project is ready to grade. (You can still edit/commit/push new changes after clicking on the Turn In button if you think of something you forgot earlier, but if the project has already been graded you will need to submit a Regrade Request in Kit to indicate that the project has been updated. Whether regrade requests are granted depends on the grader's workload and the significance of the project modifications.)
When you're done, get started on the Disassembler Utilities programming project, the first step of the Disassembler project, one of two major projects in this course.