The C Framework Top LiteralsTesting code examples Contents

Testing code examples

Starting with the next chapter, we look at the C programming language and and its features and usage. As you read these chapters, you should want to try the various constructs and operations so that you fully understand how they operate. You can do this by writing a series of small C programs and then compiling and executing each of these programs. This chapter introduces a second method to practice using the C programming language. This method provides a clean, simple interface with minimal overhead for your practice.

This second method uses a program called quickc. It is designed for testing and experimentation. We expect you to write your projects and lab programs and exams using the traditional edit-compile-test process described previously. You should use quickc when you want to just do some quick checks or tests on pieces of C code. While we believe that quickc will be beneficial to your studies, it is not required. If you prefer to use the traditional edit-compile-test cycle for everything that you do with the C programming language, then you can skip the remainder of this chapter.

The quickc program is provided to help you quickly test some of the code examples in the book. For example, suppose you see some code fragment that is preceded with the C comment //test, as in:

    //test
    printf("Hello, world\n");

With the quickc program, you can copy and paste the code fragment at the quickc prompt, press the <Enter> key, and see the result of the code fragment being executed.

Using quickc

For example, here is the quickc program starting up in a terminal window. To the terminal window prompt (in this case $), you would type quickc:

    $ quickc
    >

The quickc prompt is the "greater than" sign. Pasting the above code fragment would look like:

    $ quickc
    >     //test
    +     printf("Hello, world\n");
    + 

At this point, press the <Enter> key and you will see the fragment compiled (as part of an automatically generated C program) and executed:

    $ quickc
    >     //test
    +     printf("Hello, world\n");
    + 
    compiling the program...
    running the program...
    Hello, world
    > 

To exit the quickc program, type the q character followed by the <Enter> key. The quickc program can do lots of other tasks; typing the h character brings up a menu of these additional tasks.

If you make a mistake entering some code, you can use the up and down arrow keys to recover a statement, which you can then edit, using the backspace, delete, and left and right arrow keys. Pressing <Enter> at this point adds the edited line to the program.

Installing quickc

To get the quickc program, first retrieve it from the ACP server:

    wget troll.cs.ua.edu/ACP-C/quickc.c

Then compile it with the command:

    gcc -Wall quickc.c -o quickc -lm -lreadline

If you see an error that the symbol free_history_entry is not defined, edit quickc.c and change the line near the top that reads:

    #define FREE_HISTORY 1

to read:

    #define FREE_HISTORY 0

and recompile. Once compiled, place the quickc executable in a directory that's part of your search path, say ~/bin/, /usr/local/bin/ or /usr/bin/.

lusth@cs.ua.edu


The C Framework Top LiteralsTesting code examples Contents