應該做什麼:每輸入一個新字符到NSMutableString數字後,將輸入的字符串組中的所有數字打印出來。那麼如果當前字符不是數字,它會檢查它的+或x或*, - 。如果它是其中之一,那麼它會將其附加到數組並將其打印出來。輸出中文字符而不是數字? Objective C
什麼做的它:1.4.3中國
`Please enter math: 12+56x45
2012-05-02 23:52:06.538 CALC[1921:403] 퀱
2012-05-02 23:52:06.541 CALC[1921:403] 퀱퀲
2012-05-02 23:52:06.542 CALC[1921:403] running array (
"+"
)
2012-05-02 23:52:06.543 CALC[1921:403] 퀱퀲퀵
2012-05-02 23:52:06.544 CALC[1921:403] 퀱퀲퀵퀶
2012-05-02 23:52:06.544 CALC[1921:403] 퀱퀲퀵퀶큸
2012-05-02 23:52:06.545 CALC[1921:403] 퀱퀲퀵퀶큸퀴
2012-05-02 23:52:06.546 CALC[1921:403] 퀱퀲퀵퀶큸퀴퀵`
問題:我相信它有,當我沒有else if
部分它工作正常運行的代碼與單字符char current = [InputString characterAtIndex:i];
做不過。正如你所看到的,雖然字符串中的字符數是預期的數字,但問題似乎是它們的語言錯誤。
我的代碼:
int main()
{
char userInput[99];
NSMutableString *number = [NSMutableString string];
int i;
printf("Please enter math: ");
scanf("%s", userInput);
fpurge(stdin);
NSString *InputString = [NSString stringWithUTF8String:userInput];
NSMutableArray *broken = [NSMutableArray array];
for (i=0; i < [InputString length]; i++) {
char current = [InputString characterAtIndex:i];
NSString *cur = [NSString stringWithFormat:@"%c" , current];
if (isalnum(current)) {
[number appendString:[NSString stringWithCharacters:¤t length:1]];
NSLog(@"%@", number);
}
else if (current == '+'|| current == 'x'||current == '*'||current == '-') {
[broken addObject:[NSString stringWithFormat:cur]];
NSLog(@"running array %@", broken);
}
}
return 0;
}
其實韓文韓文不是中文。 http://unicode-table.com/en/D036/ –