不知道为什么会出错,希望大家能帮忙说一下问题- #import <Foundation/Foundation.h>
- int main(int argc, const char * argv[]) {
- @autoreleasepool {
- //1、定义一个字典每个数字(key)对应相应的字符(value)
- NSMutableDictionary *dict=[NSMutableDictionary dictionary];
- dict.dictionary=@{@"0":@"zero",@"1":@"one",@"2":@"two",@"3":@"three",@"4":@"four",@"5":@"five",@"6":@"six",@"7":@"seven",@"8":@"eight",@"9":@"nine"};
- //2、定义一个整型变量用于接收输入的数字
- printf("请输入一个整数\n");
- int a;
- scanf("%d",&a);
- //3、定义一个可变字符串用于接收数字对应的value值,
- NSMutableString *mstr=[NSMutableString string];
-
- //定义一个不可变数组用于存储输入的数字
-
- NSString *str=[NSString stringWithFormat:@"%d",a];
-
- for (int i=0; i<str.length; i++) {
- //取出每一个数字
- unichar ch=[str characterAtIndex:i];
- //printf("%c\n",ch);
- //将ch转换成nsnumber
- NSNumber *num=[NSNumber numberWithUnsignedShort:ch-48];
- NSLog(@"%@",num);
- //存储转换的元素@"zero",@"one",@"two",@"three",@"four",@"five",@"six",@"seven",@"eight",@"nine"
- [mstr appendString:[dict objectForKey:num]];
- //添加空格
- [mstr appendString:@" "];
- NSLog(@"%@",mstr);
- }
- }
- return 0;
- }
复制代码 [mstr appendString:[dict objectForKey:num]];这一句出现报错报错显示的是*** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[__NSCFString appendString:]: nil argument',希望大家能帮忙啊。
|
|