我在目标使用和xCode中使用scanf函数,但是当我运行我的代码时它不会要求我输入任何值,但是它会自动获取一些垃圾值并执行整个程序,任何一个帮助如何使xCode使用scanf,以便用户在执行整个代码之前可以在控制台中输入一些值。
int a ;
int b ;
int c = a * b;
NSLog(@"Welcome to the multiplication calculator");
NSLog(@"\n");
NSLog(@"what would you like to choose for first value?");
scanf("%i", &a);
NSLog(@"\n");
NSLog(@"What would you like to input for the second value?");
scanf("%i", &b);
NSLog(@"Here is your product");
NSLog(@"\n");
NSLog(@"a * b =%i", c);
控制台输出
2016-02-29 15:57:18.457 HandShakes[51576:12008859] Welcome to the multiplication calculator
2016-02-29 15:57:18.458 HandShakes[51576:12008859]
2016-02-29 15:57:18.458 HandShakes[51576:12008859] what would you like to choose for first value?
(lldb) 9
error: '9' is not a valid command.
error: Unrecognized command '9'.
2016-02-29 15:57:56.736 HandShakes[51576:12008859]
2016-02-29 15:57:59.687 HandShakes[51576:12008859] What would you like to input for the second value?
(lldb) 9
error: '9' is not a valid command.
error: Unrecognized command '9'.
2016-02-29 15:58:21.886 HandShakes[51576:12008859] Here is your product
2016-02-29 15:58:25.584 HandShakes[51576:12008859]
2016-02-29 15:58:27.091 HandShakes[51576:12008859] a * b =-556193768
(lldb)