Modified main.c and tested in Unix