Sections 0101, 0102, 0103 and Honors, Fall 1995
Tuesday December 5, 1995
Assigned Reading: 16.1 - 16.6
Handouts (available on-line): none
Attendance was taken.
We discussed the material covered this semester.
We concentrated on programming skills rather than the C programming
language. We learned that having a library with many useful functions
makes programming simpler and less error prone. The conclusion that
students should draw from this experience is that writing lots of
small useful functions is a good way to write large programs.
- Next, we looked at how the function scanf from
the stdio.h interface works. This is the function
you would use if you did not use GetInteger, and
GetReal from the course library. The function
scanf takes pointers to variables as parameters
(parameters passed by reference) so it can store the user's input
in those variables.
- Our first program using
scanf simply reads in an integer and a double
and prints them out. Sample run.
- Our second example shows
the consequence of forgetting the & in front
of the variable passed to scanf: you get a core dump.
- Our third example shows
two alternate forms of scanf called sscanf
and fscanf. These functions respectively read the
input from a given string or a file instead of the keyboard.
- Our fourth example shows
that scanf can be used to read in several integers
per line. The value returned by scanf is actually
the number of variables it was able to fill in, and not
the value stored in the variable. If scanf encounters
the end-of-file character (control-D on UNIX), then it returns
a -1. Sample runs.
- Our fifth example shows that
using scanf to read in several variables can be confusing
to the user. In this program, we try to read in an integer
followed by a double. The results could be confusing to
the user because it is not always clear where the integer ends.
- Now that we have seen how scanf works we can look
at how GetInteger is implemented in the source code
of the simpio library.
We also examined the strategy used for the GetLine
function that allows us to read in a string without setting
a limit on the length of the input.
- We looked at the standard C string library. A complete
description of these functions can be found in
the manual pages
on UNIX by issuing the man string command.
The functions in the standard string library offer
some of the same capabilities as the course library, but
do not check for errors as rigorously as the string functions
from the course library. Also, to use the string functions
in the standard C library, you will have to allocate space
for the strings yourself. We looked at the source code for
some of the string functions in the course library
strilib.c. We discussed
how the functions: IthChar, Concat, and
SubString work. Competent programmers should avoid
using functions like IthChar and Concat
because they are much slower than the standard routines.
- The SCEQ (Student Course Evaluation Questionaire)
survey was passed out.
Wed Dec 6 09:37:05 EST 1995
Richard Chang, firstname.lastname@example.org