开发者

How to get inout to an NSString?

开发者 https://www.devze.com 2023-03-14 11:01 出处:网络
How to get input from an NSString as scanf开发者_如何学Go (\"%@\", &str); doesn\'t work?scanf will read into a C string and not into a NSString (as far as I know). So, to do what you\'re trying to

How to get input from an NSString as scanf开发者_如何学Go ("%@", &str); doesn't work?


scanf will read into a C string and not into a NSString (as far as I know). So, to do what you're trying to do you need to first read your input into a C string (i.e. str) and then make that into an NString as follows

myString = [NSString stringWithUTF8String:str];

By the way, you don't need to pass the address of str i.e. &str if str is an array. Simply do:

scanf("%s",str);
0

精彩评论

暂无评论...
验证码 换一张
取 消