Adding K&R C exercise 8-7, based off nice SO answer