The solution for the 1st task. There are some small cosmetic issues with reading from the command line as fgets reads EOF as well.