rewrite the c code from Zed. A. Shaw's online book, learn c the hard way with c++