The problem is the line 7 => while (opt=getopt(argc,argv,":hw:ra")!=-1)
The = ( atribution operator ) have a lower precedence than the != ( diferent operator ), in other words, your code on this line, is avaliable in this form => while ( opt = ( getopt(argc,argv,":hw:ra") ) != -1 ).
As you see, the getopt function are compared with the "-1" before the opt variable get the value.
To fix the problem, just put the parentheses on the right place.