Solved Problem 8 in Python: next in C?