rewrote 3-6 K&R ex with use of an allocator