I think this code and error are self explanatory, but I do not know why?
Environment:
OS: Mac OS X 10.6.1.
compiler: i686-apple-darwin10-gcc-4.2.1
code:
include # 1 & lt; Stdio.h & gt; # 2 included & lt; Stdlib.h & gt; 3 # include & lt; Netdb.h & gt; Add # 4 & lt; Sys / socket.h & gt; 5 6 in 7 main (int arguments, four ** argv) 8 {9 characters * pt, ** ppt; 10 Composition Host * HPTR; 11 characters Straw [32]; 12 13 // PTR = AGRV [1]; 14 ptr = "www.google.com"; 15 16 If ((hptr = gethostbyname (ptr)) == tap) {17 printf ("gethostbyname error for host:% s \ n", ptr); 18 19} 20 printf ("official hostname:% s \ n", hptr-> h_name); For 21 22 (PPTR => HPTR-> H_ aliases; * PPTR! = Null; PPTR ++) 23 printf ("nickname:% s \ n", * PPTR); 24 25 switches (HPTR-> H.A. AdPrip) {26 case AF_INET: 27 cases AF_INET6: 28PPTR = HPTR- & gt; H_ADR_list; 29 (30; 30; (* * pptr! = NULL; pptr ++) 31 printf ("address:% s \ n", inet_ntop (hptr-> h_addrtype, * pptr, str, sizeof (str))) ; 32 break; 33 Default: 34 printf ("unknown address type \ n"); 35 breaks; 36} 37 returns 0; 38}
compiler and executed output below Given:
zhumatoMacBook: CPUs zhu $ gcc gethostbynameemo.c gethostbynameemo.c: 'main' in function: Gethostbynameemo.c: 31: Warning: format '% s' to' char * 'Type, but logic 2 has' int' zhumatoMacBook type: CProjects zhu $ ./a.out official hostname: www.l.google.com alias: www.google .com Segmentation error
Why am I getting draft warnings and this can be the reason for the division's fault?
Comments
Post a Comment