Note that there are some explanatory texts on larger screens.

plurals
  1. POwarning: format ‘%s’ expects type ‘char *’, but argument 2 has type ‘int’
    primarykey
    data
    text
    <p>I think this code and error is self-explanatory, but I don't know why?<br/><br/> Environment:<br/> OS: Mac OS X 10.6.1<br/> Compiler: i686-apple-darwin10-gcc-4.2.1<br/><br/> code:</p> <pre><code> 1 #include &lt;stdio.h&gt; 2 #include &lt;stdlib.h&gt; 3 #include &lt;netdb.h&gt; 4 #include &lt;sys/socket.h&gt; 5 6 int 7 main(int argc, char **argv) 8 { 9 char *ptr, **pptr; 10 struct hostent *hptr; 11 char str[32]; 12 13 //ptr = argv[1]; 14 ptr = "www.google.com"; 15 16 if ((hptr = gethostbyname(ptr)) == NULL) { 17 printf("gethostbyname error for host:%s\n", ptr); 18 19 } 20 printf("official hostname:%s\n", hptr-&gt;h_name); 21 22 for (pptr = hptr-&gt;h_aliases; *pptr != NULL; pptr++) 23 printf(" alias:%s\n", *pptr); 24 25 switch (hptr-&gt;h_addrtype) { 26 case AF_INET: 27 case AF_INET6: 28 pptr = hptr-&gt;h_addr_list; 29 30 for (; *pptr != NULL; pptr++) 31 printf(" address:%s\n", inet_ntop(hptr-&gt;h_addrtype, *pptr, str, sizeof(str))); 32 break; 33 default: 34 printf("unknown address type\n"); 35 break; 36 } 37 return 0; 38 } </code></pre> <p><br/> compiler and executed output below:</p> <pre><code>zhumatoMacBook:CProjects zhu$ gcc gethostbynamedemo.c gethostbynamedemo.c: In function ‘main’: gethostbynamedemo.c:31: warning: format ‘%s’ expects type ‘char *’, but argument 2 has type ‘int’ zhumatoMacBook:CProjects zhu$ ./a.out official hostname:www.l.google.com alias:www.google.com Segmentation fault </code></pre> <p>Why am I getting the format warning and could this be the cause of the segmentation fault?</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload