What it should do: Take the inputted string group all the numbers and print out every time a new character is appended to the NSMutableString number. Then if the current char is not a number it checks if its + or x, or *, -. If it is one of those then it appends that to an array and prints it out.
What its doing: Outputting chinese
`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] 퀱퀲퀵퀶큸퀴퀵`
Issue: I believe it has to do with the unichar char current = [InputString characterAtIndex:i]; however when i run the code without the else if part it works properly. As you can see though the number of characters that are part of the string are the expected number, the issue seems to be they are in the wrong language.
My code:
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;
}
I see you’ve “converted” the
charinto anNSString. Why don’t you try to appendcurto the string you are printing? So change:to: