1

I successfully use NSFileHandle to read keyboard input:

NSFileHandle * keyboard = [NSFileHandle fileHandleWithStandardInput];
NSData *inputData = [keyboard availableData];
NSString * input =[[NSString alloc] initWithData:inputData encoding:NSUTF8StringEncoding];

As the user types, only the first character of input is echoed on the screen. For example, if I type hello, only h is echoed on the screen. However the full input is read into the string.

The proper echo behavior works in Xcode 4.2. I'm currently using Xcode 4.5.

UPDATE

Giving up on NSFileHandle for now, I tried to use scanf. However there's the same echoing issue. scanf code:

char word[4];
scanf("%s",word);
NSString * input = [[NSString alloc] initWithBytes:word length:4 encoding:NSUTF8StringEncoding];
soundsmitten
  • 90
  • 2
  • 8
  • What does your NSLog statement look like? Try changing all of the mutable stuff to non mutable. As for the enter key, substringWithRange will take it out. – fiacobelli Oct 02 '12 at 03:31

1 Answers1

1

This is a bug in Xcode 4.5. When the console is refreshed all echoed input is revealed.

soundsmitten
  • 90
  • 2
  • 8