Program does not work when passing argument via command line [message #1448538] |
Mon, 20 October 2014 04:30 |
amit chaudhary Messages: 6 Registered: October 2014 |
Junior Member |
|
|
Hello,
I am working on a project which involves socket programming. When I pass an argument through command line the code does not work i.e. after reading the argument, there is a call to a socket connect in C++, which does not work. The code gets stuck at line :
extern int connect (int __fd, __CONST_SOCKADDR_ARG __addr, socklen_t __len);
inside socket.h
Even when I simply pass an argument but does not use it, the program is not running.
I am using Eclipse Luna 4.4.1 on Opensuse 13.1.
Here is the example code for executable test:
int main(int argc, char** argv){
int date = 20141020;
TestClient client;
client.connect(host,port,clientID);
}
The above code compiles successfully. Now from the command line:
a) ./test
the above works fine
b) ./test 20141020
the above does not work and the code gets stuck at client.connect line. Note that I am not using the argument in any way.
I have also checked if the code reads the argument correctly as follows:
int main(int argc, char** argv){
int date = std::atoi(argv[1]);
std::cout<<date<<std::endl;
TestClient client;
client.connect(host,port,clientID);
}
Now when i run the program as ./test 20141020, I get on the output screen 20141020 but then the code gets stuck at line client.connect.
Please guide me as to how can I resolve this issue.
|
|
|
Powered by
FUDForum. Page generated in 0.03850 seconds