5 <style|<tuple|book|style-bk>>
10 <section|Ch. 1: A Tutorial Introduction>
12 <subsection|Sec. 1.1: Getting Started>
17 <item*|Exercise 1-1>Run the \P<verbatim|hello, world>\Q program on your
18 system. Experiment with leaving out parts of the program, to see what
19 error messages you get.
21 <item*|Exercise 1-2>Experiment to find out what happens when
22 <cpp|printf>'s argument string contains <cpp|\\><em|c>, where <em|c> is
23 some character not listed above.
26 <subsection|Sec. 1.2: Variables and Arithmetic Expressions>
29 <item*|Exercise 1-3>Modify the temperature conversion program to bring a
30 heading above the table.
32 <item*|Exercise 1-4>Write a program to bring the corresponding Celsius to
36 <subsection|Sec. 1.3: The For Statement>
39 <item*|Exercise 1-5>Modify the temperature conversion program to print
40 the table in reverse order, that is, from <math|300> degrees to <math|0>.
43 <subsection|Sec. 1.4: Symbolic Constants>
45 <subsection|Sec. 1.5: Character Input and Output>
47 <subsubsection|Sec. 1.5.1: File Copying>
50 <item*|Exercise 1-6>Verify that the expression <cpp|getchar() != EOF> is
53 <item*|Exercise 1-7>Write a program to print the value of <cpp|EOF>.
56 <subsubsection|Sec. 1.5.2: Character Counting>
58 <subsubsection|Sec. 1.5.3: Line Counting>
61 <item*|Exercise 1-8>Write a program to count blanks, tabs, and newlines.
63 <item*|Exercise 1-9>Write a program to copy its input to its output,
64 replacing each string of one or more blanks by a single blank.
66 <item*|Exercise 1-10>Write a program to copy its input to its output,
67 replacing each tab by <cpp|\\t>, each backspace by <cpp|\\b>, and each
68 backslash by <cpp|\\\\>. This makes tabs and backspaces visible in an
72 <subsubsection|Sec. 1.5.4: Word Counting>
75 <item*|Exercise 1-11>How would you test the word program? What kinds of
76 input are most likely to uncover bugs if there are any?
78 <item*|Exercise 1-12>Write a program that prints its input one word per
82 <subsection|Sec. 1.6: Arrays>
85 <item*|Exercise 1-13>Write a program to print a histogram of the lengths
86 of words in its input. IT is easy to draw the histogram with the bars
87 horizontal; a vertical orientation is more challenging.
89 <item*|Exercise 1-14>Write a program to print a histogram of the
90 frequencies of different characters in its input.
93 <subsection|Sec 1.7: Functions>
96 <item*|Exercise 1-15>Rewrite the temperature conversion program of
97 Section 1.2 to use a function for conversion.
100 <subsection|Sec 1.8: Arguments\UCall by Value>
102 <subsection|Sec 1.9: Character Arrays>
105 <item*|Exercise 1-16>Revise the main routine of the longest-line program
106 so it will correctly print the length of arbitrarily long input lines,
107 and as much as possible of the text.
109 <item*|Exercise 1-17>Write a program to print all input lines that are
110 longer than <math|80> characters.
112 <item*|Exercise 1-18>Write a program to remove trailing blanks and tabs
113 from each line of input, and to delete entirely blank lines.
115 <item*|Exercise 1-19>Write a function <cpp|reverse(s)> that reverses the
116 character string <cpp|s>. Use it to write a program that reverses its
117 input a line at a time.
120 <subsection|Sec 1.10: External Variables and Scope>
123 <item*|Exercise 1-20>Write a program <cpp|detab> that replaces tabs in
124 the input with the proper number of blanks to space to the next tab stop.
125 Assume a fixed set of tab stops, say every <em|n> columns. Should <em|n>
126 be a variable or a symbolic parameter?
128 <item*|Exercise 1-21>Write a program <cpp|entab> that replaces strings of
129 blanks by the minimum number of tabs and blanks to achieve the same
130 spacing. Use the same tab stops as for <cpp|detab>. When either a tab or
131 a single blank would suffice to each a tab stop, which should be given
134 <item*|Exercise 1-22>Write a program to \Pfold\Q long input lines into
135 two or more shorter lines after the last non-blank character that occurs
136 before the <em|n>-th column of input. Make sure your program does
137 something intelligent with very long lines, and if there are no blanks or
138 tabs before the specified column.
140 <item*|Exercise 1-23>Write a program to remove all comments from a
141 <name|C> program. Don't forget to handle quoted strings and character
142 constants properly. <name|C> comments do not nest.
144 <item*|Exercise 1-24>Write a program to check a <name|C> program for
145 rudimentary syntax errors like unbalanced parentheses, brackets and
146 braces. Don't forget about quotes, both single and double, escape
147 sequences, and comments. (This program is hard if you do it in full
151 <section|Ch2: Types, Operators, and Expressions>
153 <subsection|Sec 2.1: Variable names>
155 <subsection|Sec 2.2: Data Types and Sizes>
158 <item*|Exercise 2-1>Write a program to determine the ranges of
159 <cpp|char>, <cpp|short>, <cpp|int>, and <cpp|long> variables, both
160 <cpp|signed> and <cpp|unsigned>, by printing appropriate values from
161 standard headers and by direct computation. Harder if you compute them:
162 determine the ranges of the various floating-point types.
165 <subsection|Sec 2.3: Constants>
167 <subsection|Sec 2.4: Declarations>
169 <subsection|Sec 2.5: Arithmetic Operators>
171 <subsection|Sec 2.6: Relational and Logical Operators>
174 <item*|Exercise 2-2>Write a loop equivalent to the <cpp|for> loop above
175 without using <cpp|&&> or <cpp|\|\|>.
178 <subsection|Sec 2.7: Type Conversions>
181 <item*|Exercise 2-3>Write the function <cpp|htoi(s)>, which converts a
182 string of hexadecimal digits (including an optional <cpp|0x> or <cpp|0X>)
183 into its equivalent integer value. The allowable digits are <cpp|0>
184 through <cpp|9>, <cpp|a> through <cpp|f>, and <cpp|A> through <cpp|F>.
187 <subsection|Sec 2.8: Increment and Decrement Operators>
190 <item*|Exercise 2-4>Write an alternate version of <cpp|squeeze(s1,s2)>
191 that deletes each character in <cpp|s1> that matches any character in the
192 <em|string> <cpp|s2>.
194 <item*|Exercise 2-5>Write the function <cpp|any(s1,s2)>, which returns
195 the first location in the string <cpp|s1> where any character fromt he
196 string <cpp|s2> occurs, or <cpp|-1> if <cpp|s1> contains no characters
197 from <cpp|s2>. (The standard library function <cpp|strpbrk> does the same
198 job but returns a pointer to the location.)
201 <subsection|Sec 2.9: Bitwise Operators>
204 <item*|Exercise 2-6>Write a function <cpp|setbits(x,p,n,y)> that returns
205 <cpp|x> with the <cpp|n> bits that begin at position <cpp|p> set to the
206 rightmost <cpp|n> bits of <cpp|y>, leaving the other bits unchanged.
208 <item*|Exercise 2-7>Write a function <cpp|invert(x,p,n)> that returns
209 <cpp|x> with the <cpp|n> bits that begin at position <cpp|p> inverted
210 (i.e. <math|1> changed into <math|0> and vice versa), leaving the others
213 <item*|Exercise 2-8>Write a function <cpp|rightrot(x,n)> that returns the
214 value of the integer <cpp|x> rotated to the right by <cpp|n> bit
218 <subsection|Sec 2.10: Assignment Operators and Expressions>
221 <item*|Exercise 2-9>In a two\<#2019\>s complement number system, <cpp|x
222 &= (x-1)> deletes the rightmost <math|1>-bit in <cpp|x>. Explain why. Use
223 this observation to write a faster version of <cpp|bitcount>.
226 <subsection|Sec 2.11: Conditional Expressions>
229 <item*|Exercise 2-10>Rewrite the function <cpp|lower>, which converts
230 upper case letters to lower case, with a conditional expression instead
234 <subsection|Sec 2.12: Precedence and Order of Evaluation>
236 <section|Ch3: Control Flow>
238 <subsection|Sec 3.1: Statements and Blocks>
240 <subsection|Sec 3.2: If-Else>
242 <subsection|Sec 3.3: Else-If>
245 <item*|Exercise 3-1>Our binary search makes two tests inside th eloop,
246 when one would suffice (at the price of more tests outside). Write a
247 version with only one test inside the loop and measure the difference in
251 <subsection|Sec 3.4: Switch>
254 <item*|Exercise 3-2>Write a function <cpp|escape(s,t)> that converts
255 characters like newline and tab into visible escape sequences like
256 <cpp|\\n> and <cpp|\\t> as it copies the string <cpp|t> to <cpp|s>. Use a
257 <cpp|switch>. Write a function for the other direction as well,
258 converting escape sequences into the real characters.
261 <subsection|Sec 3.5: Loops>
264 <item*|Exercise 3-3>Write a function <cpp|expand(s1,s2)> that expands
265 shorthand notations like <cpp|a-z> in the string <cpp|s1> into the
266 equivalent complete list <cpp|abc...xyz> in <cpp|s2>. Allow for letters
267 of either case and digits, and be prepared to handle cases like
268 <cpp|a-b-c> and <cpp|a-z0-9> and <cpp|-a-z>. Arrange that a leading or
269 trailing <cpp|-> is taken literally.
273 Sec 3.6: Loops\UDo-while
277 <item*|Exercise 3-4>In a two's complement number representation, our
278 version of <cpp|itoa> does not handle the largest negative number, that
279 is, the value of <cpp|n> equal to <math|-<around*|(|2<rsup|<text|wordsize>-1>|)>>.
280 Explain why not. Modify it to print that value correctly, regardless of
281 the machine on which it runs.
283 <item*|Exercise 3-5>Write the function <cpp|itob(n,s,b)> that converts
284 the integer <cpp|n> into a base <cpp|b> character representation in the
285 string <cpp|s>. In particular, <cpp|itob(n,s,16)> formats <cpp|n> as a
286 hexadecimal integer in <cpp|s>.
288 <item*|Exercise 3-6>Write a version of <cpp|itoa> that accepts three
289 arguments instead of two. The third argument is a minimum field width;
290 the converted number must be padded with blanks on the left if necessary
291 to make it wide enough.
294 <subsection|Sec 3.7: Break and Continue>
296 <subsection|Sec 3.8: Goto and Labels>
298 <section|Ch 4: The C Preprocessor>
300 <subsection|Sec 4.1: Basics of Functions>
303 <item*|Exercise 4-1>Write the function <cpp|strrindex(s,t)>, which
304 returns the position of the <em|rightmost> occurence of <cpp|t> in
305 <cpp|s>, or <cpp|-1> if there is none.
308 <subsection|Sec 4.2: Functions Returning Non-integers>
311 <item*|Exercise 4-2>Extend <cpp|atof> to handle scientific notation of
318 where a floating-point number may be followed by <cpp|e> or <cpp|E> and
319 an optionally signed exponent.
322 <subsection|Sec 4.3: External Variables>
325 <item*|Exercise 4-3>Given the basic framework, it's straightforward to
326 extend the calculator. Add the modulus (<cpp|%>) operator and provisions
327 for negative numbers.
329 <item*|Exercise 4-4>Add commands to print the top element of the stack
330 without popping, to duplicate it, and to swap the top two elements. Add a
331 command to clear the stack.
333 <item*|Exercise 4-5>Add access to library functions like <cpp|sin>,
334 <cpp|exp>, and <cpp|pow>. See <cpp|\<less\>math.h\<gtr\>> in Appendix B,
337 <item*|Exercise 4-6>Add commands for handling variables. (It's easy to
338 provide twenty-six variables with single-letter names.) Add a variable
339 for the most recently printed value.
341 <item*|Exercise 4.7>Write a routine <cpp|ungets(s)> that will push back
342 an entire string onto the input. Should <cpp|ungets> know about <cpp|buf>
343 and <cpp|bufp>, or should it just use <cpp|ungetch>?
345 <item*|Exercise 4-8>Suppose that there will never be more than one
346 character of pushback. Modify <cpp|getch> and <cpp|ungetch> accordingly.
348 <item*|Exercise 4-9>Our <cpp|getch> and <cpp|ungetch> do not handle a
349 pushed-back <cpp|EOF> correctly. Decide what their properties ought to be
350 if an <cpp|EOF> is pushed back, then implement your design.
352 <item*|Exercise 4-10>An alternate organization uses <cpp|getline> to read
353 an entire input line; this makes <cpp|getch> andj <cpp|ungetch>
354 unnecessary. Revise the calculator to use this approach.
357 <subsection|Sec 4.4: Scope Rules>
359 <subsection|Sec 4.5: Header Files>
361 <subsection|Sec 4.6: Static Variables>
363 <subsection|Sec 4.7: Register Variables>
365 <subsection|Sec 4.8: Block Structure>
367 <subsection|Sec 4.9: Initialization>
369 <subsection|Sec 4.10: Recursion>
372 <item*|Exercise 4-12>Adapt the ideas of <cpp|printd> to write a recursive
373 version of <cpp|itoa>; that is, convert an integer into a string by
374 calling a recursive routine.
376 <item*|Exercise 4-13>Write a recursive version of the function
377 <cpp|reverse(s)>, which reverses the string <cpp|s> in place.
380 <subsection|Sec 4.11: The C Preprocessor>
382 <subsubsection|Sec 4.11.1: File Inclusion>
384 <subsubsection|Sec 4.11.2: Macro Substitution>
387 <item*|Exercise 4-14>Define a macro <cpp|swap(t,x,y)> that interchanges
388 two arguments of type <cpp|t>. (Block structure will help.)
391 <subsubsection|Sec 4.11.3: Conditional Inclusion>
393 <section|Ch 5: Pointers and Arrays>
395 <subsection|Sec 5.1: Pointers and Addresses>
397 <subsection|Sec 5.2: Pointers and Function Arguments>
400 <item*|Exercise 5-1>As written, <cpp|getint> treats a <cpp|+> or <cpp|->
401 not followed by a digit as a valid representation of zero. Fix it to push
402 such a character back onto the input.
404 <item*|Exercise 5-2>Write <cpp|getfloat>, the floating-point analog of
405 <cpp|getint>. What type does <cpp|getfloat> return as its function value?
408 <subsection|Sec 5.3: Pointers and Arrays>
410 <subsection|Sec 5.4: Address Arithmetic>
412 <subsection|Sec 5.5: Character Pointers and Functions>
415 <item*|Exercise 5-3>Write a pointer version of the function <cpp|strcat>
416 that we showed in Chapter 2: <cpp|strcat(s,t)> copies the string <cpp|t>
417 to the end of <cpp|s>.
419 <item*|Exercise 5-4>Write the function <cpp|strend(s,t)>, which returns
420 <cpp|1> if the string <cpp|t> occurs at the end of the string <cpp|s>,
423 <item*|Exercise 5-5>Write versions of the library functions
424 <cpp|strncpy>, <cpp|strncat>, and <cpp|strncmp>, which operate on at most
425 the first <cpp|n> characters of their argument strings. For example,
426 <cpp|strncpy(s,t,n)> copies at most <cpp|n> characters of <cpp|t> to
427 <cpp|s>. Full descriptions are in Appendix B.
429 <item*|Exercise 5-6>Rewrite appropriate programs from earlier chapters
430 and exercises with pointers instead of array indexing. Good possibilities
431 include <cpp|getline> (Chapters 1 and 4), <cpp|atoi>, <cpp|itoa>, and
432 their variants (Chapters 2, 3, and 4), <cpp|reverse> (Chapter 3), and
433 <cpp|strindex> and <cpp|getop> (Chapter 4).
436 <subsection|Sec 5.6: Pointer Arrays; Pointers to Pointers>
439 <item*|Exercise 5-7>Rewrite <cpp|readlines> to store lines in an array
440 supplied by <cpp|main>, rather than calling <cpp|alloc> to maintain
441 storage. How much faster is the program?
444 <subsection|Sec 5.7: Multi-dimensional Arrays>
447 <item*|Exercise 5-8>There is no error checking in <cpp|day_of_year> or
448 <cpp|month_day>. Remedy this defect.
451 <subsection|Sec 5.8: Initialization of Pointer Arrays>
453 <subsection|Sec 5.9: Pointers vs. Multi-dimensional Arrays>
456 <item*|Exercise 5-9>Rewrite the routines <cpp|day_of_year> and
457 <cpp|month_day> with pointers instead of reindexing.
460 <subsection|Sec 5.10: Command-line Arguments>
465 <item*|Exercise 5-10>Write the program <cpp|expr>, which evaluates a
466 reverse Polish expression fromt he command line, where each operator or
467 operand is a separate argument. For example,
470 expr \ 2 \ 3 \ 4 \ + \ *
473 evaluates <math|2\<times\><around*|(|3+4|)>>.
475 <item*|Exercise 5-11>Modify the programs <cpp|entab> and <cpp|detab>
476 (written as exercises in Chapter 1) to accept a list of tab stops as
477 arguments. Use the default tab settings if there are no arguments.
479 <item*|Exercise 5-12>Extend <cpp|entab> and <cpp|detab> to accept the
483 entab -<text|<em|m>> +<text|<em|n>>
486 to mean tab stops every <em|n> columns, starting at column <em|m>. Choose
487 convenient (for the user) default behavior.
489 <item*|Exercise 5-13>Write the program <cpp|tail>, which prints the last
490 <em|n> lines of its input. By default, <em|n> is <math|10>, let us say,
491 but it canb e changed by an optional argument so that
497 prints the last <em|n> lines. The program should behave rationally no
498 matter how unreasonable the input or the value of <em|n>. Write the
499 program so it makes the best use of available storage; lines should be
500 stored as in the sorting program of Section 5.6, not in a two-dimensional
504 <subsection|Sec 5.11: Pointers to Functions>
507 <item*|Exercise 5-14>Modify the sort program to handle a <cpp|-r> flag,
508 which indicates sorting in reverse (decreasing) order. Be sure that
509 <cpp|-r> works with <cpp|-n>.
511 <item*|Exercise 5-15>Add the option <cpp|-f> to fold upper and lower case
512 together, so that case distinctions are not made during sorting; for
513 example, <cpp|a> and <cpp|A> compare equal.
515 <item*|Exercise 5-16>Add the <cpp|-d> (\Pdirectory\Q) option, which makes
516 comparisons only on letters, numbers, and blanks. Make sure it works in
517 conjunction with <cpp|-f>.
519 <item*|Exercise 5-17>Add a field-handling capability, so sorting may be
520 done on fields within lines, each field sorted according to an
521 independent set of options. (The index for this book was sorted with
522 <cpp|-df> for the index category and <cpp|-n> for the page numbers.)
525 <subsection|Sec 5.12: Complicated Declarations>
528 <item*|Exercise 5-18>Make <cpp|dcl> recover from input errors.
530 <item*|Exercise 5-19>Modify <cpp|undcl> so that it does not add redundant
531 parentheses to declarations.
533 <item*|Exercise 5-20>Expand <cpp|dcl> to handle declarations with
534 function argument types, qualifiers like <cpp|const>, and so on.
537 <section|Ch 6: Structures>
539 <subsection|Sec 6.1: Basics of Structures>
541 <subsection|Sec 6.2: Structures and Functions>
543 <subsection|Sec 6.3: Arrays of Structures>
546 <item*|Exercise 6-1>Our version of <cpp|getword> does not properly handle
547 underscores, string constants, comments, or preprocessor control lines.
548 Write a better version.
551 <subsection|Sec 6.4: Pointers to Structures>
553 <subsection|Sec 6.5: Self-referential Structures>
556 <item*|Exercise 6-2>Write a program that reads a <name|C> program and
557 prints in alphabetical order each group of variable names that are
558 identical in the first <math|6> characters, but different somewhere
559 thereafter. Don't count words within strings and comments. Make <math|6>
560 a parameter that can be set from the command line.
562 <item*|Exercise 6-3>Write a cross-referencer that prints a list of all
563 words in a document, and, for each word, a lis tof the line numbers on
564 which it occurs. Remove noise words like \Pthe\Q, \Pand\Q, and so on.
566 <item*|Exercise 6-4>Write a program that prints the distinct words in its
567 input sorted into decreasing order of frequency of occurrence. Precede
568 each word by its count.
571 <subsection|Sec 6.6: Table Lookup>
574 <item*|Exercise 6-5>Write a function <cpp|undef> that will remove a name
575 and definition from the table maintained by <cpp|lookup> and
578 <item*|Exercise 6-6>Implement a simple version of the <cpp|#define>
579 processor (i.e., no arguments) suitable for use with <name|C> programs,
580 based on the routines of this section. You may also find <cpp|getch> and
581 <cpp|ungetch> helpful.
584 <subsection|Sec 6.7: Typedef>
586 <subsection|Sec 6.8: Unions>
588 <subsection|Sec 6.9: Bit-fields>
590 <section|Ch 7: Input and Output>
592 <subsection|Sec 7.1: Standard Input and Output>
595 <item*|Exercise 7-1>Write a program that converts upper case to lower or
596 lower case to upper, depending on the name it is invoked with, as found
600 <subsection|Sec 7.2: Formatted Output\UPrintf>
603 <item*|Exercise 7-2>Write a program that will print arbitrary input in a
604 sensible way. AS a minimum, it ishould print non-graphic characters in
605 octal or hexadecimal according to local custom, and break long text
609 <subsection|Sec 7.3: Variable-length Argument Lists>
612 <item*|Exercise 7-3>Revise <cpp|minprintf> to handle more of the other
613 facilities of <cpp|printf>.
616 <subsection|Sec 7.4: Formatted Input\UScanf>
619 <item*|Exercise 7-4>Write a private version of <cpp|scanf> analogous to
620 <cpp|minprintf> from the previous section.
622 <item*|Exercise 7-5>Rewrite the postfix calculator of Chapter 4 to use
623 <cpp|scanf> and/or <cpp|sscanf> to do the input and number conversion.
626 <subsection|Sec 7.5: File Access>
628 <subsection|Sec 7.6: Error Handling\UStderr and Exit>
630 <subsection|Sec 7.7: Line Input and Output>
633 <item*|Exercise 7-6>Write a program to compare two files, printing the
634 first line where they differ.
636 <item*|Exercise 7-7>Modify the pattern finding program of Chapter 5 to
637 take its input from a set of named files or, if no files are named as
638 arguments, from the standard input. Should the file name be printed when
639 a matching line is found?
641 <item*|Exercise 7-8>Write a program to print a set of files, starting
642 each new one on a new page, with a title and a running page count for
646 <subsection|Sec 7.8: Miscellaneous Functions>
648 <subsubsection|Sec 7.8.1: String Operations>
650 <subsubsection|Sec 7.8.2: Character Class Testing and Conversion>
652 <subsubsection|Sec 7.8.3: Ungetc>
654 <subsubsection|Sec 7.8.4: Command Execution>
656 <subsubsection|Sec 7.8.5: Storage Management>
658 <subsubsection|Sec 7.8.6: Mathematical Functions>
660 <subsubsection|Sec 7.8.7: Random Number Generation>
663 <item*|Exercise 7-9>Functions like <cpp|isupper> can be implemented to
664 save space or to save time. Explore both possibilities.
667 <section|Ch 8: The UNIX System Interface>
669 <subsection|Sec 8.1: File Descriptors>
671 <subsection|Sec 8.2: Low Level I/O\URead and Write>
673 <subsection|Sec 8.3: Open, Creat, Close, Unlink>
676 <item*|Exercise 8-1>Rewrite the program <cpp|cat> from Chapter 7 using
677 <cpp|read>, <cpp|write>, <cpp|open>, and <cpp|close> instead of their
678 standard library equivalents. Perform experiemnts to determine the
679 relative speeds of the two versions.
682 <subsection|Sec 8.4: Random Access\ULseek>
684 <subsection|Sec 8.5: Example\UAn Implementation of Fopen and Getc>
687 <item*|Exercise 8-2>Rewrite <cpp|fopen> and <cpp|_fillbuf> with fields
688 instead of explicit bit operations. Compare code size and execution
691 <item*|Exercise 8-3>Design and write <cpp|_flushbuf>, <cpp|fflush>, and
694 <item*|Exercise 8-4>The standard library function
697 int fseek(FILE *fp, long offset, int origin)
700 is identical to <cpp|lseek> except that <cpp|fp> is a file pointer
701 instead of a file descriptor and the return value is an <cpp|int> status,
702 not a position. Write <cpp|fseek>. Make sure that your <cpp|fseek>
703 coordinates properly with the buffering done for the other functions of
707 <subsection|Sec 8.6: Example\UListing Directories>
710 <item*|Exercise 8-5>Modify the <cpp|fsize> program to print the other
711 information contained in the inode entry.
714 <subsection|Sec 8.7: Example\UA Storage Allocator>
717 <item*|Exercise 8-6>The standard library function <cpp|calloc(n,size)>
718 returns a pointer to <cpp|n> objects of size <cpp|size>, with the storage
719 initialized to zero. Write <cpp|calloc>, by calling <cpp|malloc> or by
722 <item*|Exercise 8-7><cpp|malloc> accepts a size request without checking
723 its plausibility; <cpp|free> believes that the block it is asked to free
724 contains a valid size field. Improve these routins so they take more
725 pains with error checking.
727 <item*|Exercise 8-8>Write a routine <cpp|bfree(p,n)> that will free an
728 arbitrary block <cpp|p> of <cpp|n> characters into the free list
729 maintained by <cpp|malloc> and <cpp|free>. By using <cpp|bfree>, a user
730 can add a static or external array to the free list at any time.
740 <associate|page-medium|papyrus>
746 <associate|auto-1|<tuple|1|1|../../../../.TeXmacs/texts/scratch/no_name_10.tm>>
747 <associate|auto-10|<tuple|1.1.5.3|?|../../../../.TeXmacs/texts/scratch/no_name_10.tm>>
748 <associate|auto-100|<tuple|1.8.7|?|../../../../.TeXmacs/texts/scratch/no_name_10.tm>>
749 <associate|auto-11|<tuple|1.1.5.4|?|../../../../.TeXmacs/texts/scratch/no_name_10.tm>>
750 <associate|auto-12|<tuple|1.1.6|?|../../../../.TeXmacs/texts/scratch/no_name_10.tm>>
751 <associate|auto-13|<tuple|1.1.7|?|../../../../.TeXmacs/texts/scratch/no_name_10.tm>>
752 <associate|auto-14|<tuple|1.1.8|?|../../../../.TeXmacs/texts/scratch/no_name_10.tm>>
753 <associate|auto-15|<tuple|1.1.9|?|../../../../.TeXmacs/texts/scratch/no_name_10.tm>>
754 <associate|auto-16|<tuple|1.1.10|?|../../../../.TeXmacs/texts/scratch/no_name_10.tm>>
755 <associate|auto-17|<tuple|1.2|?|../../../../.TeXmacs/texts/scratch/no_name_10.tm>>
756 <associate|auto-18|<tuple|1.2.1|?|../../../../.TeXmacs/texts/scratch/no_name_10.tm>>
757 <associate|auto-19|<tuple|1.2.2|?|../../../../.TeXmacs/texts/scratch/no_name_10.tm>>
758 <associate|auto-2|<tuple|1.1|?|../../../../.TeXmacs/texts/scratch/no_name_10.tm>>
759 <associate|auto-20|<tuple|1.2.3|?|../../../../.TeXmacs/texts/scratch/no_name_10.tm>>
760 <associate|auto-21|<tuple|1.2.4|?|../../../../.TeXmacs/texts/scratch/no_name_10.tm>>
761 <associate|auto-22|<tuple|1.2.5|?|../../../../.TeXmacs/texts/scratch/no_name_10.tm>>
762 <associate|auto-23|<tuple|1.2.6|?|../../../../.TeXmacs/texts/scratch/no_name_10.tm>>
763 <associate|auto-24|<tuple|1.2.7|?|../../../../.TeXmacs/texts/scratch/no_name_10.tm>>
764 <associate|auto-25|<tuple|1.2.8|?|../../../../.TeXmacs/texts/scratch/no_name_10.tm>>
765 <associate|auto-26|<tuple|1.2.9|?|../../../../.TeXmacs/texts/scratch/no_name_10.tm>>
766 <associate|auto-27|<tuple|1.2.10|?|../../../../.TeXmacs/texts/scratch/no_name_10.tm>>
767 <associate|auto-28|<tuple|1.2.11|?|../../../../.TeXmacs/texts/scratch/no_name_10.tm>>
768 <associate|auto-29|<tuple|1.2.12|?|../../../../.TeXmacs/texts/scratch/no_name_10.tm>>
769 <associate|auto-3|<tuple|1.1.1|?|../../../../.TeXmacs/texts/scratch/no_name_10.tm>>
770 <associate|auto-30|<tuple|1.3|?|../../../../.TeXmacs/texts/scratch/no_name_10.tm>>
771 <associate|auto-31|<tuple|1.3.1|?|../../../../.TeXmacs/texts/scratch/no_name_10.tm>>
772 <associate|auto-32|<tuple|1.3.2|?|../../../../.TeXmacs/texts/scratch/no_name_10.tm>>
773 <associate|auto-33|<tuple|1.3.3|?|../../../../.TeXmacs/texts/scratch/no_name_10.tm>>
774 <associate|auto-34|<tuple|1.3.4|?|../../../../.TeXmacs/texts/scratch/no_name_10.tm>>
775 <associate|auto-35|<tuple|1.3.5|?|../../../../.TeXmacs/texts/scratch/no_name_10.tm>>
776 <associate|auto-36|<tuple|1.3.6|?|../../../../.TeXmacs/texts/scratch/no_name_10.tm>>
777 <associate|auto-37|<tuple|1.3.7|?|../../../../.TeXmacs/texts/scratch/no_name_10.tm>>
778 <associate|auto-38|<tuple|1.3.8|?|../../../../.TeXmacs/texts/scratch/no_name_10.tm>>
779 <associate|auto-39|<tuple|1.4|?|../../../../.TeXmacs/texts/scratch/no_name_10.tm>>
780 <associate|auto-4|<tuple|1.1.2|?|../../../../.TeXmacs/texts/scratch/no_name_10.tm>>
781 <associate|auto-40|<tuple|1.4.1|?|../../../../.TeXmacs/texts/scratch/no_name_10.tm>>
782 <associate|auto-41|<tuple|1.4.2|?|../../../../.TeXmacs/texts/scratch/no_name_10.tm>>
783 <associate|auto-42|<tuple|1.4.3|?|../../../../.TeXmacs/texts/scratch/no_name_10.tm>>
784 <associate|auto-43|<tuple|1.4.4|?|../../../../.TeXmacs/texts/scratch/no_name_10.tm>>
785 <associate|auto-44|<tuple|1.4.5|?|../../../../.TeXmacs/texts/scratch/no_name_10.tm>>
786 <associate|auto-45|<tuple|1.4.6|?|../../../../.TeXmacs/texts/scratch/no_name_10.tm>>
787 <associate|auto-46|<tuple|1.4.7|?|../../../../.TeXmacs/texts/scratch/no_name_10.tm>>
788 <associate|auto-47|<tuple|1.4.8|?|../../../../.TeXmacs/texts/scratch/no_name_10.tm>>
789 <associate|auto-48|<tuple|1.4.9|?|../../../../.TeXmacs/texts/scratch/no_name_10.tm>>
790 <associate|auto-49|<tuple|1.4.10|?|../../../../.TeXmacs/texts/scratch/no_name_10.tm>>
791 <associate|auto-5|<tuple|1.1.3|?|../../../../.TeXmacs/texts/scratch/no_name_10.tm>>
792 <associate|auto-50|<tuple|1.4.11|?|../../../../.TeXmacs/texts/scratch/no_name_10.tm>>
793 <associate|auto-51|<tuple|1.4.11.1|?|../../../../.TeXmacs/texts/scratch/no_name_10.tm>>
794 <associate|auto-52|<tuple|1.4.11.2|?|../../../../.TeXmacs/texts/scratch/no_name_10.tm>>
795 <associate|auto-53|<tuple|1.4.11.3|?|../../../../.TeXmacs/texts/scratch/no_name_10.tm>>
796 <associate|auto-54|<tuple|1.5|?|../../../../.TeXmacs/texts/scratch/no_name_10.tm>>
797 <associate|auto-55|<tuple|1.5.1|?|../../../../.TeXmacs/texts/scratch/no_name_10.tm>>
798 <associate|auto-56|<tuple|1.5.2|?|../../../../.TeXmacs/texts/scratch/no_name_10.tm>>
799 <associate|auto-57|<tuple|1.5.3|?|../../../../.TeXmacs/texts/scratch/no_name_10.tm>>
800 <associate|auto-58|<tuple|1.5.4|?|../../../../.TeXmacs/texts/scratch/no_name_10.tm>>
801 <associate|auto-59|<tuple|1.5.5|?|../../../../.TeXmacs/texts/scratch/no_name_10.tm>>
802 <associate|auto-6|<tuple|1.1.4|?|../../../../.TeXmacs/texts/scratch/no_name_10.tm>>
803 <associate|auto-60|<tuple|1.5.6|?|../../../../.TeXmacs/texts/scratch/no_name_10.tm>>
804 <associate|auto-61|<tuple|1.5.7|?|../../../../.TeXmacs/texts/scratch/no_name_10.tm>>
805 <associate|auto-62|<tuple|1.5.8|?|../../../../.TeXmacs/texts/scratch/no_name_10.tm>>
806 <associate|auto-63|<tuple|1.5.9|?|../../../../.TeXmacs/texts/scratch/no_name_10.tm>>
807 <associate|auto-64|<tuple|1.5.10|?|../../../../.TeXmacs/texts/scratch/no_name_10.tm>>
808 <associate|auto-65|<tuple|1.5.11|?|../../../../.TeXmacs/texts/scratch/no_name_10.tm>>
809 <associate|auto-66|<tuple|1.5.12|?|../../../../.TeXmacs/texts/scratch/no_name_10.tm>>
810 <associate|auto-67|<tuple|1.6|?|../../../../.TeXmacs/texts/scratch/no_name_10.tm>>
811 <associate|auto-68|<tuple|1.6.1|?|../../../../.TeXmacs/texts/scratch/no_name_10.tm>>
812 <associate|auto-69|<tuple|1.6.2|?|../../../../.TeXmacs/texts/scratch/no_name_10.tm>>
813 <associate|auto-7|<tuple|1.1.5|?|../../../../.TeXmacs/texts/scratch/no_name_10.tm>>
814 <associate|auto-70|<tuple|1.6.3|?|../../../../.TeXmacs/texts/scratch/no_name_10.tm>>
815 <associate|auto-71|<tuple|1.6.4|?|../../../../.TeXmacs/texts/scratch/no_name_10.tm>>
816 <associate|auto-72|<tuple|1.6.5|?|../../../../.TeXmacs/texts/scratch/no_name_10.tm>>
817 <associate|auto-73|<tuple|1.6.6|?|../../../../.TeXmacs/texts/scratch/no_name_10.tm>>
818 <associate|auto-74|<tuple|1.6.7|?|../../../../.TeXmacs/texts/scratch/no_name_10.tm>>
819 <associate|auto-75|<tuple|1.6.8|?|../../../../.TeXmacs/texts/scratch/no_name_10.tm>>
820 <associate|auto-76|<tuple|1.6.9|?|../../../../.TeXmacs/texts/scratch/no_name_10.tm>>
821 <associate|auto-77|<tuple|1.7|?|../../../../.TeXmacs/texts/scratch/no_name_10.tm>>
822 <associate|auto-78|<tuple|1.7.1|?|../../../../.TeXmacs/texts/scratch/no_name_10.tm>>
823 <associate|auto-79|<tuple|1.7.2|?|../../../../.TeXmacs/texts/scratch/no_name_10.tm>>
824 <associate|auto-8|<tuple|1.1.5.1|?|../../../../.TeXmacs/texts/scratch/no_name_10.tm>>
825 <associate|auto-80|<tuple|1.7.3|?|../../../../.TeXmacs/texts/scratch/no_name_10.tm>>
826 <associate|auto-81|<tuple|1.7.4|?|../../../../.TeXmacs/texts/scratch/no_name_10.tm>>
827 <associate|auto-82|<tuple|1.7.5|?|../../../../.TeXmacs/texts/scratch/no_name_10.tm>>
828 <associate|auto-83|<tuple|1.7.6|?|../../../../.TeXmacs/texts/scratch/no_name_10.tm>>
829 <associate|auto-84|<tuple|1.7.7|?|../../../../.TeXmacs/texts/scratch/no_name_10.tm>>
830 <associate|auto-85|<tuple|1.7.8|?|../../../../.TeXmacs/texts/scratch/no_name_10.tm>>
831 <associate|auto-86|<tuple|1.7.8.1|?|../../../../.TeXmacs/texts/scratch/no_name_10.tm>>
832 <associate|auto-87|<tuple|1.7.8.2|?|../../../../.TeXmacs/texts/scratch/no_name_10.tm>>
833 <associate|auto-88|<tuple|1.7.8.3|?|../../../../.TeXmacs/texts/scratch/no_name_10.tm>>
834 <associate|auto-89|<tuple|1.7.8.4|?|../../../../.TeXmacs/texts/scratch/no_name_10.tm>>
835 <associate|auto-9|<tuple|1.1.5.2|?|../../../../.TeXmacs/texts/scratch/no_name_10.tm>>
836 <associate|auto-90|<tuple|1.7.8.5|?|../../../../.TeXmacs/texts/scratch/no_name_10.tm>>
837 <associate|auto-91|<tuple|1.7.8.6|?|../../../../.TeXmacs/texts/scratch/no_name_10.tm>>
838 <associate|auto-92|<tuple|1.7.8.7|?|../../../../.TeXmacs/texts/scratch/no_name_10.tm>>
839 <associate|auto-93|<tuple|1.8|?|../../../../.TeXmacs/texts/scratch/no_name_10.tm>>
840 <associate|auto-94|<tuple|1.8.1|?|../../../../.TeXmacs/texts/scratch/no_name_10.tm>>
841 <associate|auto-95|<tuple|1.8.2|?|../../../../.TeXmacs/texts/scratch/no_name_10.tm>>
842 <associate|auto-96|<tuple|1.8.3|?|../../../../.TeXmacs/texts/scratch/no_name_10.tm>>
843 <associate|auto-97|<tuple|1.8.4|?|../../../../.TeXmacs/texts/scratch/no_name_10.tm>>
844 <associate|auto-98|<tuple|1.8.5|?|../../../../.TeXmacs/texts/scratch/no_name_10.tm>>
845 <associate|auto-99|<tuple|1.8.6|?|../../../../.TeXmacs/texts/scratch/no_name_10.tm>>
852 <vspace*|1fn><with|font-series|<quote|bold>|math-font-series|<quote|bold>|1<space|2spc>K&R
853 Exercises> <datoms|<macro|x|<repeat|<arg|x>|<with|font-series|medium|<with|font-size|1|<space|0.2fn>.<space|0.2fn>>>>>|<htab|5mm>>
854 <no-break><pageref|auto-1><vspace|0.5fn>