CSC230 Homework 1

Update 5/24/15:

The purpose of this assignment is to get you started writing, formatting, compiling, and executing simple C programs. This requires that you familiarize yourself with the Common Platform (NCSU Linux machines) and learn how to use gcc for compiling C source code to an executable.

This homework is to be done individually.

Learning Outcomes

Part 1: Hello World

Download hw1_starter.tar. A tar file is a container for a group of files. We have grouped together all of the files needed to get started for the homework. FTP the tar file to your AFS space and untar using the following command:

% tar xvf hw1_starter.tar

Alternatively, you can download the files individually and FTP them to your AFS space. Be careful when FTPing the expected output files. There may be differences with white space that will lead to deductions!

Open the "Hello World" program in your favorite text editor. It has been commented and formatted according to the style guidelines for the class.

The purpose of the Hello World program is to demonstrate your ability to compile a program on the common platform and to refresh your memory for writing simple functions. You will add two functions to the Hello World program (functions are basically C's version of Java methods). These functions would be written in C almost the same way they are written in Java, so if you struggle with this assignment, it's an indication you may need to brush up on your 116 and 216 knowledge. The descriptions of the functions are in the hello_world.c file.

Complete the following tasks:

Use the following command to compile your program:

% gcc -Wall -std=c99 hello_world.c -o hello_world

Use the following commands to test your program by generating an output file using redirection and then comparing your actual output of execution with our expected output from execution:

% ./hello_world > hello_actual % diff hello_expected hello_actual

If there is no output (the two files are the same) then you successfully completed the assignment!

The program you submit should be named hello_world.c.

Part 2: Mystery

Reformat and rename mystery_unformatted.c in accordance with the class style guidelines so that it is clear, consistent, and easy to read. You may use any tool you like for this purpose, including an indenting tool, an IDE, a text editor, etc.

When your program runs, the output should be exactly:

371

After reformatting the program, read the code and figure out what the program is doing (at a high level). Please add a comment to the main function in accordance with the style guidelines that explains the functionality of the program in one or two sentences.

When grading, we redirect your program's output to a file. We will then diff your output with our output. There should be NO difference (if there is a difference, the information about the difference is printed to the console). This would be done using the following commands (assuming the expected output is stored in mystery_expected):

% gcc -Wall -std=c99 mystery.c -o mystery % ./mystery > mystery_actual % diff mystery_expected mystery_actual %

You can also use the sdiff command. This will print both files side by side and allow you to find the exact inconsistencies between the files. In the command above, you would replace diff with sdiff.

The program you submit should be named mystery.c.

Instructions for Submission

This github isn't ready yet, so we'll just use submit.ncsu.edu for now. How to: If you're unfortunate enough to be submitting late (WHY???), use the "HW1_late" locker (open for 24 hours after the due date). There is an automatic 20 point deduction for late work.

We recommend that you keep the files for Homework 1 in a separate directory from your other course materials.  Assuming that this is so, use the following command (in the directory with your Homework 1 files) to tar your files:

% tar cvf <unityid>_1_homework.tar *.c

This command will tar all of the *.c files in the current directory to a file named <unityid>_1_homework.tar.  Again, please replace <unityid> with your unity id.  As the tar is created, all the files added to the tar will be listed so you can confirm that the appropriate files are submitted. Follow the Style Guidelines for CSC230. Make sure your program compiles on the common platform cleanly (no errors or warnings), with the required compiler options.

Rubric

Part 1: hello_world.c

+10 for compiling on common platform with gcc -Wall -std=c99 options, with no warnings

+20 for correct results (as per the diff command shown above)

+20 for changing the name in the comments and maintaining the style guidelines for the course (!!!)

-5 for not including your name

-5 for formatting that is inconsistent, makes no sense, or is hard to read (e.g., no tabs)

Part 2: mystery.c

+20 for changing the formatting to match the style guidelines for the course

-5 for each formatting mistake (e.g., no tabs), up to 20 points

+20 for correctly describing the program functionality.

+10 for correct results (as per the diff command shown above)

Commons sources of Error