final version of my greedy.c using while loops