Update main.c

Add writeMode and readMode, change code alignment