Hi,
This must be very simple but since coming from Java world I feel a bit in the woods in this case.
while (operator != 'E') {
NSLog(@"Enter:");
scanf("%lf %c", &value2, &operator);
switch (operator) {
case 'S':
[deskCalc setAccumulator:value2];
break;
case 'E':
break;
case '+':
[deskCalc add:value2];
break;
case '-':
[deskCalc subtract:value2];
break;
case '/':
[deskCalc divide:value2];
break;
case '*':
[deskCalc multiply:value2];
break;
default:
NSLog(@"Unknown command");
break;
}
NSLog(@"=%g", [deskCalc accumulator]);
}
Now if I enter just 'e' or some other characters without entering the number first the program goes into loop like this:
2010-02-08 13:44:38.690 Calculator[89939:a0f] Enter:
2010-02-08 13:44:38.691 Calculator[89939:a0f] Unknown command
2010-02-08 13:44:38.691 Calculator[89939:a0f] =10
2010-02-08 13:44:38.692 Calculator[89939:a0f] Enter:
2010-02-08 13:44:38.692 Calculator[89939:a0f] Unknown command
2010-02-08 13:44:38.693 Calculator[89939:a0f] =10
Why scanf doesn't block the thread and ask for correct input again?
Thanks Noi