I am trying to use 'gethostbyname'. If I hardcode a host name directly into the function call it works great. However, I am trying to pass user input into this function. I believe my problem may because the array I am passing to the function has many trailing whitespaces.
void connectHost(char *hostname)
{
int n;
//This works
//n = gethostbyname("irc.ubuntu.com");
//This always returns NULL
n = gethostbyname(hostname);
if(n == NULL)
{
printf("Host Not Found.");
}
}
int main()
{
char hostname[256];
fgets(hostname,255,stdin);
connectHost(hostname);
}
So what is the best way to just pass the host name to the function? Should I not be using fgets?
Thanks!