COS 126
Exercise Set 6
Answers

These programming exercises are intended help review the material on recursion, pointers, and dynamic memory allocation. Do not turn in solutions.

  1. Implement this version of itoa: char *itoa(int n, int b) returns a dynamically allocated null-terminated string giving the character representation of n in base b. The caller must deallocate the returned string. For example:
    char *s = itoa(875, 5);
    printf("%s\n", s);
    Prints 12001 and deallocates s.

Answers

Try to implement these programs before looking at the suggested solutions.

  1. itoa4.c.

Copyright © 1996 David R. Hanson / drh@cs.princeton.edu
$Revision: 1.2 $ $Date: 1996/10/23 13:05:31 $