Xcode编写objectiveC,scanf不执行是为什么?
以下程序中的scanf为什么不执行啊,而是直接给n值为0,一直到程序结束。为什么?应该怎么解决呢?百度好久无果。请大神指点。
int main()
{
NSAutoreleasePool* pool = [[NSAutoreleasePool alloc]init];
Fraction* aFraction = [[Fraction alloc]init];
Fraction* sum = [[Fraction alloc]init],*sum2;
int i,n,pow2;
[sum setTo:0 over:1];
NSLog(@"Enter your value for n:");
scanf("%i",&n);
pow2 = 2;
for(i = 0;i<=n;++i)
{
[aFraction setTo:1 over:pow2];
sum2 = [sum add:aFraction];
[sum release];
sum = sum2;
pow2*=2;
}
NSLog(@"如果求和到2的%i次幂,结果是%g",n,[sum convertToNum]);
[aFraction release];
[sum release];
[pool drain];
return 0;
}