Update main.c

fix for accessing invalid index