k&r; exercise 1.5 - improve the solution