The Art and Science of
C
Instructor’s Manual
Eric S. Roberts
Stanford University
Stanford, California
Instructor’s Manual for The Art and Science of C Converting from Pascal to C 2
Section 1
Converting from Pascal to C
From the late 1970s to the early 1990s, Pascal was the standard language for introductory computer science
instruction throughout the United States and in much of the rest of the world as well. Over the last several years,
however, many institutions have been moving away from Pascal as the language begins to show its age. Although
some schools have taken a different direction, many—including Stanford—have adopted ANSI C as the language of
instruction for the introductory course. Along with its object-oriented successor C++, ANSI C is the dominant
language in the industry today. Teaching C early in the curriculum gives students additional preparation in the
language they are most likely to use and makes for a smoother transition to C++ when that material appears later in
the curriculum.
The reasons behind Stanford’s decision to adopt C in the introductory course are outlined in the “To the Instructor”
section of The Art and Science of C and discussed in detail in the paper “Using C in CS1: Evaluating the Stanford
experience,” which is included in Section 8 of this Instructor’s Manual. The purpose of this section is not to
recapitulate those reasons but to talk instead about strategies and tactics for making the change.
The two most important lessons to pass on from our experience at Stanford are the following:
1. The transition will not be easy. Anyone who suggests that changing the implementation language in an
established curriculum is a simple task would be better employed marketing snake oil. The overall design of the
introductory programming course depends to a surprising extent on the mechanics of the language system used to
provide instruction; changing the language therefore has implications that affect the entire curriculum. The
instructional staff needs to rethink how to present material, someone must rewrite the assignments, and the
institutional structures supporting the introductory course must adapt to the new conditions.
2. The advantages of making the change will be greater than anticipated. At Stanford, our original goal in making
the transition was to produce students in the new introductory course who programmed as effectively in C as
their predecessors had in Pascal. Because C programming skills are more useful in subsequent courses, we
believed that having the students attain the previous level of skill would be sufficient. What we’ve found is that
students are much better programmers coming out of the revised course than they ever were before. They are
more excited about the material, have worked harder to attain a level of mastery, and understand certain essential
concepts—most notably modularity and data abstraction—much better than their predecessors did.
There are several things you can do to simplify the transition.
• Take advantage of the benefits afforded by the library-based approach. Because there are more details involved
in learning C than in learning Pascal, it is important to simplify the conceptual process for students at the
introductory level. In our experience, the most effective way to do so is to use the abstraction capabilities of the
language to hide its complexity until the students are better able to understand it. The essential characteristics of
the library-based approach are discussed in Section 2.
• Prepare any affected staff for the transition. Before making a change of this magnitude, it is important to make
sure that the teaching staff responsible for the course—including TAs and anyone else who has direct contact
with students in the course—have a chance to prepare for the transition. In the first year, we continued to teach a
Pascal-based course while running a small, experimental C section. This phased introduction gave us time to
refine the course materials and develop a cadre of support staff with the necessary expertise.
Instructor’s Manual for The Art and Science of C Converting from Pascal to C 3
• Recognize that the conversion will take time to stabilize. One of the realities that we failed to understand when
we first made the change at Stanford was how much we depend on the campus community as a whole to provide
support for introductory teaching. In most years, students rely on older students in the dormitories for assistance.
When we began to convert the introductory course, the students had no one to consult beyond the course staff,
which was already overloaded trying to institute the changes. After a year, however, the informal support
structures had been largely reestablished.
Instructor’s Manual for The Art and Science of C The Library-Based Approach 4
Section 2
The Library-Based Approach
Using The Art and Science of C makes it possible to teach C to introductory students without forcing them to
assimilate all the details that make C difficult as a first language. For this purpose, the text uses a library-based
approach that emphasizes the principle of abstraction.
Adopting the library-based approach has the following advantages:
1. Libraries and modular development are covered in considerable detail early in the presentation. Students using
this text are exposed to the design and implementation of library packages much earlier than in most introductory
courses. As a result, they complete the course with a much deeper understanding of not only the mechanics of
libraries but also the associated concepts of abstraction and information hiding. By the middle of the first course,
students understand the idea of an interface and appreciate the difference in perspective between the client and
the implementation. This understanding makes it much easier for them to structure applications that adhere to the
principles of modern software engineering.
2. The libraries conceal many of the most difficult and confusing aspects of the language. For the introductory
student, the process of learning C is complicated by the fact that many of the concepts that one needs for simple
programs are complex operations in the C domain. One of the classic examples is the scanf function, which
requires students to use the & operator and to understand in detail the process of character I/O before they write
their first program. Because they are using a library containing a much simpler collection of input functions,
students do not have to confront these difficulties until much later in the course.
3. The use of libraries makes it possible to present concepts in a logical, easily assimilated order. The C
programming language was designed for use by experienced programmers. As a result, understanding the
underlying logic of the language often requires more detailed knowledge of programming concepts than the
introductory student is likely to have. For example, C’s approach to strings makes sense if you already
understand arrays, which in turn make sense if you understand pointers. From the student’s perspective,
however, the internal dependencies among these concepts make learning much more difficult because strings are
in fact conceptually simpler than the concepts on which strings are based. Introducing a library like strlib.h
breaks the internal dependency and makes it possible to introduce the concepts in an order that makes them much
easier for new students to grasp.
4. Using libraries dramatically extends a student’s ability to write exciting applications. The graphics library
introduced in Chapter 7 does more than introduce the notion of a library interface. By giving the students tools to
draw simple figures on the computer screen, the graphics.h interface frees them from the sterile world of the
text-based user interface and opens up the more exciting domain of computer graphics. Particularly now that
most students have experience working with computers that offer graphical capabilities, being able to build
graphical applications is essential to keeping student interest high.
5. The text demonstrates the power of libraries by using them. The libraries in the text serve not only as tools but
also as objects of study in their own right. As the text reveals the implementation of the libraries, students gain a
better understanding of how libraries work and how they can be used to control the complexity of a large
software application.
The details and advantages of the library-based approach are considered more thoroughly in two papers included in
Section 8 of this Instructor’s Manual: “Using C in CS1: Evaluating the Stanford experience” and “A C-based
graphics library for CS1.”
Instructor’s Manual for The Art and Science of C Obtaining Copies of the Libraries 5
Section 3
Obtaining Copies of the Libraries
To make it possible to teach ANSI C at the introductory level, The Art and Science of C is designed around several
special libraries—collectively known as the cslib library—that hide much of the complexity associated with C until
students are better equipped to understand how everything works. To use the text, you must have access to the
cslib library on your own machine. Although the code for the cslib library is included in Appendix B of the text,
it is much easier to obtain an electronic copy from the following FTP site:
ftp://ftp.awl.com/cseng/authors/roberts/cs1-c
With the exception of the graphics library presented in Chapter 7, the cslib library is entirely standard and requires
nothing more than what is provided as part of ANSI C. Thus, if you do not intend to use the graphics library, it
doesn’t matter what version of cslib you get—they are all the same. However, because the mechanics of
displaying screen images depend on the hardware and software configuration of each computer, you need an
implementation of the graphics library that is appropriate to your computing environment.
To find the right version of the cslib library for your computing platform:
1. Check to see if your computing platform is any of the following:
• A Macintosh running THINK C or Symantec C++
• An IBM PC (or clone) running the Borland C/C++ compiler
• Any Unix system running the X Window System
For each of these platforms, there is a corresponding implementation of the libraries specific to that computing
environment. To obtain it, you should connect to the appropriate subdirectory and follow the instructions in that
README file. You should also check the README file on the FTP directory to see if new library releases have been
made since this guide was published.
2. If you are using one of the hardware systems from the preceding list with a different compiler or operating
system, consider purchasing the software necessary to make your platform correspond to one of the standard
implementations. For example, if you own an IBM PC but use some compiler other than the Borland compiler, it
might be worth installing the Borland compiler so that you can use all the features provided by the libraries,
including interactive graphics. Although implementations for other platforms may be released in the future,
adapting the graphics library is not a high-priority task now that there is at least one implementation for each of
the major hardware platforms used in most universities.
3. If you cannot obtain the desired software or are using some other type of machine, get a copy of the standard
version of the library code from the standard subdirectory.
This implementation defines the libraries in an ANSI-standard form but does not provide any on-screen graphics.
The standard implementation of the graphics library instead writes a file containing a text representation of the
image suitable for printing on any PostScript printer.
4. Although the standard library implementation is highly portable and works without change on every machine
I’ve tried, there may be some systems that cannot support it. If you find that your system does not support the
standard libraries for some reason, you should try the simplified version of the library, which provides the
minimum level of support necessary to run the programs in the text.
Subdirectory index
The top-level ftp directory contains no relevant files other than a README file. The files you need for the various
libraries are collected in the following subdirectories, each of which is described in more detail in the sections that
follow:
simplified This subdirectory contains the simplest possible version of the library code and matches the
code printed in Appendix B of the text (except for two minor changes introduced to increase