Previous: 14.4 Summary
Up: 14 Storage Class and Scope
Previous Page: 14.4 Summary
- Modify the functions getchr() and ungetchr()
of Section 14.1.6 so that any
number of characters, up to a maximum of 40, can be put back into the input
stream. Use these functions in a program that reads characters and puts all
vowels back until a newline is read. At that point, the program writes the
vowels that were put back in the input stream.
Write a program that reads scores from a file, but uses a dynamically
allocated array. Assume that the first line of the file has the number of
students. Read the value of the number of students, dynamically allocate an
array for the scores, read the scores, and print them out.
- Modify 2 so a student record
is a structure. The file lists the number of
students in the first line and the number of exams in the second line. Assume
that an old weighted average is present as the last column in the file and that
the first two columns are student name and an id
number. Use dynamic allocation to write a menu-driven grading program that
allows all possible options: add student, delete student, change grade, add new
exam scores, compute various averages, etc.
- Write a program that reads and sorts an array of numbers. Use a function to
sort the array, but use a pointer to a function to make a comparison of two
numbers. If the function returns True, swap the elements; otherwise, the
elements are in correct order. Test the program with functions to sort in
increasing and in decreasing order.
- Write a program that reads an array of transliterated strings that
represent equivalent strings in some language. The strings are to be sorted
according to the alphabet of that language. First order the ASCII characters
according to the alphabet of that language. Then use a function that returns
True if two characters are ordered in a correct sequence. Use the function to
sort the array of strings.
Use a structure with two members to represent either a complex number or a
rational number. We will call each of them an ordered pair number. Write a
generic function to add two ordered pair numbers where the addition is
performed by a function a pointer to which is passed as an argument.
- Repeat 6 to subtract two ordered pair numbers.
- Repeat 6 to multiply two ordered pair numbers.
- Repeat 6 to divide two ordered pair numbers.
Write a lexical analyzer that finds tokens of the following type in a
string:
identifier
integer
float
operator
end of string
Repeat 10 without using an external variable.
Use a pointer to a character
as an argument to a function get_token()
which indirectly returns the character
read, but unused in a token.
- Repeat 11, but use a static character variable
in get_token() instead of
indirectly returning the character read but unused. The static character will
remain unchanged and may be used for the start of the next token.
Previous: 14.4 Summary
Up: 14 Storage Class and Scope
Previous Page: 14.4 Summary