Some code inspired by the K&R book on C programming