k&r; exercise 1.4 - rewrite with tests