gethostbyname xcode issues

风格不统一 提交于 2019-12-31 05:19:47

问题


Hey guys, I'm new at this stuff, but I'm trying to use gethostname() to work using xcode and the ipad. I've tried a couple of things, but they all seem to freeze up.

So when I just do:

host = gethostbyname("website.com");

that works fine. I'd like to be able to change the website from within the program though.

I've tried:

const char *server = [Website_NSString UTF8String];                    
host = gethostbyname(server);

 

const char *server = [Website_NSString cStringUsingEncoding:NSASCIIStringEncoding];     
host = gethostbyname(server);

 

const char *server[256];        
[Website_NSString getCString:server maxLength:256 encoding:NSASCIIStringEncoding];    
host = gethostbyname(Website_NSString);

and

host = gethostbyname(Website_NSString);

They've either come up with a the warning: Passing argument 1 of 'gethostbyname' from incompatible pointer type, or no warning at all. Still everytime the app just freezes. Please help.


回答1:


I'm an idiot. If I do:

char server[256];
[Website_NSString getCString:server maxLength:256 encoding:NSASCIIStringEncoding];
host = gethostbyname(server);

It works fine.



来源:https://stackoverflow.com/questions/5145895/gethostbyname-xcode-issues

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!