R
ruroma
Hello,
I have one problem, and can think of two possible solutions but I
can't manage to make them work. I'm open to other suggestions if you
thik is better.
[Brief Situation] The main function calls sendSocket, but I don't know
how to tell it where to send the socket. ( I think I'm messing it up
with pointers)
struct hostent *hp;
sendSocket(){
hp= gethostbyname(PROBLEM HERE);
}
main(){
sendSocket();
}
[Possible First Solution]
This would be probably the best approach to what I need. Ask the user
for the hostname
sendSocket(){
char hostname[256];
printf("Enter hostname: ");
fgets ( hostname, 256, stdin );
hp= gethostbyname(¿WHAT SHOULD I PUT HERE?);
}
[Possible Second Solution]
A way to make argc and argv available outside the main function.
struct hostent *hp;
sendSocket(){
hp = gethostbyname(argv[1]);
}
main(int argc; char *argv[]){
sendSocket();
}
Any suggestion? Thanks
I have one problem, and can think of two possible solutions but I
can't manage to make them work. I'm open to other suggestions if you
thik is better.
[Brief Situation] The main function calls sendSocket, but I don't know
how to tell it where to send the socket. ( I think I'm messing it up
with pointers)
struct hostent *hp;
sendSocket(){
hp= gethostbyname(PROBLEM HERE);
}
main(){
sendSocket();
}
[Possible First Solution]
This would be probably the best approach to what I need. Ask the user
for the hostname
sendSocket(){
char hostname[256];
printf("Enter hostname: ");
fgets ( hostname, 256, stdin );
hp= gethostbyname(¿WHAT SHOULD I PUT HERE?);
}
[Possible Second Solution]
A way to make argc and argv available outside the main function.
struct hostent *hp;
sendSocket(){
hp = gethostbyname(argv[1]);
}
main(int argc; char *argv[]){
sendSocket();
}
Any suggestion? Thanks