将NSString转换为char问题 [英] casting a NSString to char problem

查看:130
本文介绍了将NSString转换为char问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想将我的NSString转换为常量char
,代码如下所示:

i want to casting my NSString to a constant char the code is shown below :

NSString *date = @"12/9/2009";
char datechar = [date UTF8String]

NSLog(@"%@",datechar);

然而它返回警告
赋值从指针生成整数而没有强制转换
并且无法正确打印字符,有人可以告诉我是什么问题

however it return the warning assignment makes integer from pointer without a cast and cannot print the char properly,can somebody tell me what is the problem

推荐答案

尝试更多类似的事情:

NSString* date = @"12/9/2009";
char* datechar = [date UTF8String];
NSLog(@"%s", datechar);

你需要使用char *而不是char,你必须使用%s打印C字符串%@(%@仅适用于objective-c id类型)。

You need to use char* instead of char, and you have to print C strings using %s not %@ (%@ is for objective-c id types only).

这篇关于将NSString转换为char问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆