You are never going to write to the screen when you leave off the 3rd argument.
int fd3=open(ARGV[3],O_WRONLY);
with an empty or garbage ARGV[3]
will likely set fd3
to -1
, which is not 0
. So you will never write to STDOUT_FILENO, but instead write to an invalid file descriptor.