In the linux programmers manual the function has the following declaration:
struct hostent *gethostbyname(const char *name);
This means the parameter must be a char array (or string in layman terms). A quoted string such as "yahoo.com" can be used directly when calling the function.
The following code is a working example on how gethostbyname works:
#include <stdio.h>
#include <string.h>
#include <netdb.h>
int main(){
struct hostent* h=gethostbyname("yahoo.com");
printf("Hostname: %s\n", h->h_name);
printf("Address type #: %d\n", h->h_addrtype);
printf("Address length: %d\n", h->h_length);
char text[50]; // allocate 50 bytes (a.k.a. char array)
strcpy(text,"bing.ca"); //copy string "bing.ca" to first 7 bytes of the array
h=gethostbyname(text); //plug in the value into the function. text="bing.ca"
printf("Hostname: %s\n", h->h_name);
printf("Address type #: %d\n", h->h_addrtype);
printf("Address length: %d\n", h->h_length);
return 0;
}
I called it twice. Once for yahoo.com and once for bing.ca and I retrieved the hostname, the address type number and the address length (which is the number of bytes required to store the IP).
For calling the bing address, I allocated a char array, filled it with a string then passed that char array as a parameter to the function.