1

I have to use scanf() for accepting name of user in NSString object.
If i use %s then it will show me error. My Code is :

NSString *name;
scanf("%s",&name); //It is showing error
scanf("%@",&name); //It also show me error

What I should do?

Abbas Mulani
  • 693
  • 2
  • 8
  • 18

1 Answers1

3

You can't use scanf(), since it can't take a NSString object as an argument. You can first scan characters in a char * c-'string' and after that create a NSString from it with - (id)initWithCString:(const char *)nullTerminatedCString encoding:(NSStringEncoding)encoding.

Alexander
  • 8,067
  • 1
  • 34
  • 45