Restructured main.c so that it can read inputs longer than the buffer size. It is now consistent with plan.txt