-2

How to get input from an NSString as scanf ("%@", &str); doesn't work?

Matoe
  • 2,742
  • 6
  • 33
  • 52
  • possible duplicate of [Read input from a cocoa/foundation tool console?](http://stackoverflow.com/questions/869802/read-input-from-a-cocoa-foundation-tool-console) –  Jun 21 '11 at 01:44
  • 2
    *To* an NSString, or *from* an NSString? Your subject says one, and your question the other, and it makes a big difference in the answer... – Sherm Pendley Jun 21 '11 at 02:22

1 Answers1

1

scanf will read into a C string and not into a NSString (as far as I know). So, to do what you're trying to do you need to first read your input into a C string (i.e. str) and then make that into an NString as follows

myString = [NSString stringWithUTF8String:str];

By the way, you don't need to pass the address of str i.e. &str if str is an array. Simply do:

scanf("%s",str);
saad
  • 1,225
  • 15
  • 31