Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
scanf ("%@", &str);動作しないのでNSStringから入力を取得するにはどうすればよいですか?
scanf ("%@", &str);
scanfは、NSStringではなくC文字列に読み込まれます(私が知る限り)。したがって、実行しようとしていることを実行するには、最初に入力をC文字列(つまりstr)に読み込み、次にそれを次のようにNStringにする必要があります。
myString = [NSString stringWithUTF8String:str];
ちなみに、strが配列の場合は、strのアドレスを渡す必要はありません。単に行う:
scanf("%s",str);