EECS 2031 Software Tools, Winter 2014

Lab 1 (open lab, not in labtest mode)

Objective

Short Reference of useful Unix commands

First, open a command line window/unix prompt by starting an xterm.

What to do

First, create a few subdirectories Then create a simple ANSI-C program and compile it.
#include <stdio.h>

main() {
    printf("hello, world\n");
}
Now create a new ANSI-C program that does the following. For this, you should review these lecture slides. You may want to start with the program "getchar1.c". As far as control statements, such as if, are concerned, and logical operators, such as &&, you can use the same syntax as in Java.

Requirements

Your program must read individual characters from standard input. For the purpose of this lab, you do not need to worry about overflow. If you need details about the encoding of characters in ASCII, refer to the following Wikipedia page.

Assuming that the program is started with lab1, and given the following input from the keyboard (you have to type this):

This is a Test
0123456789
$;
^D
where the last line has the user hitting control-D. Your terminal will show the following, where input and output is intermixed.
This is a Test 
T...T
0123456789

$;
..
  
45
The reason behind this behaviour is that input from the terminal is buffered on a line-by-line basis by default. Note the (correctly) generated output from the spaces in the first line.

Hints:

Testing the program a different way

To make testing your program a little easier, you should now create a text file with your favourite editor, which contains the input for your program. For your convenience, the above test input is available here as a UNIX text file input.txt. Now you can test your program as follows.

lab1 <input.txt

This command line syntax makes the program read the standard input from the named file. Not only does this save you the work to type your input every time you want to test your program, it also ensures that you give your program exactly the same input every time. This will reduce the potential for confusion and make it easier to debug your code. Given that the input is not echoed to the terminal when you start your program in this manner, the output will (and should) only be:

T...T

..

45