Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Language IDEs » C / C++ IDE (CDT) » Program does not work when passing argument via command line(Socket does not connect when passing argument)
Program does not work when passing argument via command line [message #1448538] Mon, 20 October 2014 04:30
amit chaudhary is currently offline amit chaudharyFriend
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.
Previous Topic:Binaries not built if the folder containing the main.cpp file has the same name as the project
Next Topic:Using wrong make file?
Goto Forum:
  


Current Time: Fri Oct 04 20:31:28 GMT 2024

Powered by FUDForum. Page generated in 0.03850 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top