Verifying Results Using Input / Output Redirection and diff

Follow the steps below in order to verify whether your program generates expected results for a program. In the description below, public01.in represents the input associated with a test and public01.output the expected output. The diff utility is used to verify whether the correct output is generated.

In Unix input that you provide via the keyboard can also be provided using input redirection from a file. Likewise, output that is generated to the screen can be saved to a file by using output redirection. A program can read input from a file instead of the keyboard by using < and a file (e.g., a.out < filename). You can send output of a program to a file by using > and a file (e.g., a.out > results). Using >! will overwrite an existing file.

The Input/Output Redirection and diff Video illustrates how to use input and output redirection along with diff to verify the results of a program are correct.

Program Output When Using Input/Output Redirection

The output of a program may look different when using input/output redirection. For example, first, run the program example.c by entering the values provided in the example_input.txt file and later using input redirection with that file. The results using input/output redirection can be found at example_output.txt and

Web Accessibility