Update main.c

fix for accessing invalid index
Merge pull request #1 from ideasman42/master

Update main.c