getopt returns and int and not a char for this very reason... definitely a bad idea to cast it to a char before checking for EOF. EOF is not guaranteed to fit in a char