C++
Paper instructions:
1 Write a program to read lines and print only those containing a certain word. (For now, the word can be a constant string in the program.) The basic pattern (which I have to confess I have parroted exactly from K&R Sec. 4.1) is
while(there’s another line)
{
if(line contains word)
print the line;
}
2 Use the strstr function (mentioned in the notes) to look for the word. Be sure to include the line
#include <string.h>
at the top of the source file where you call strstr.
Rewrite the checkbook-balancing program from assignment 4 (exercise 6) to use the getwords function (from the notes) to make it easy to take the word “check” or “deposit”, and the amount, from a single line.
3 Rewrite the line-reversing function from assignment 4 (exercise 9) to use pointers.
4 Rewrite the character-counting function from assignment 5 (exercise 3) to use pointers.
5 Rewrite the string-concatenation program from assignment 5 (exercise 4) to call malloc to allocate a new piece of memory just big enough for the concatenated result. Don’t forget to leave room for the !
6 Rewrite the string-replacing function from assignment 5 (exercise 5) to use pointers.
7 Write a program to read lines of text up to EOF, and then print them out in reverse order. You can use getline to read each line into a fixed-size array (as we have been doing all along), but you will have to call malloc and make a copy of each line before you read the next one. Also, you will have to use malloc and realloc to maintain the “array” of character pointers which holds all of the lines.