0
我正在制作一个程序,您必须在控制台中输入某些内容,然后按下视图控制器上的按钮后,它将在控制台中进行打印。当我运行它时,提示被打印出来,但是当我按下按钮时输入不会被打印回来。这是我的看法Controller.m或者扫描后不出现Charf
#import "ViewController.h"
@interface ViewController()
@end
char word[40];
@implementation ViewController
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self) {
// Custom initialization
NSLog(@"Please enter a word.");
// 1
char cstring[40];
// 2
scanf("%s",cstring);
// 3
NSString *inputString = [NSString stringWithCString:cstring encoding:1];
}
return self;
}
- (IBAction)changeText:(id)sender{
NSLog(@"You entered the word '%@'", inputString);
}
@end
“控制台”是什么意思?可能是这种情况(我必须检查)iOS实际上没有设置从控制台读取stdin。 – neal
@neal通过控制台我指的是箭头指向链接图片中的东西;对不起,如果这不是它通常所称的,我不确定它的名字是什么。[link](http://www.cimgf.com/wp-content/uploads/2012/12/Screenshot-121212 -1219-AM.png) – TheIntern
这就是lldb控制台,lldb正在您的mac上运行,并通过网络与您的设备通话。你不能像这样混合tty控制台I/O。 – trojanfoe