Exercises
Starting with the structure
Does your function preserve the terminating newline? Explain why or why not.
How does your function handle lines that end in CR-LF?
How do you initialize the structure? With a separate routine? With a documented requirement for specific values in the structure?
How do you indicate end-of-file? How do you indicate that an I/O error has occurred? For errors, should your function print an error message? Explain why or why not.
Write a program that uses your function to test it, and another program to generate input data to the first program. Test your function.
Rewrite your function to use fgets() and test it. Is the new code more complex or less complex? How does its performance compare to the getc() version?
Study the V7 end(3) manpage (/usr/man/man3/end.3 in the V7 distribution). Does it shed any light on how 'sbrk(0)' might work?
Enhance ch03-memaddr.c to print out the location of the arguments and the environment. In which part of the address space do they reside?
struct line { size_t buflen; char *buf; FILE *fp; };
write your own readline() function that will read an any-length line. Don't worry about backslash continuation lines. Instead of using fgets() to read lines, use getc() to read characters one at a time.