How to convert nsstring to cString?

Warrior picture Warrior · Oct 26, 2010 · Viewed 11k times · Source

I have a nsstring(filePath), which has the path to the audio file. I want open the audio file, so I want to convert the nsstring to Cstring.

  fopen([filePath cStringUsingEncoding:1], "r");

is the above line is correct or not, because I can also use fopen([filePath cString], "r");. In some websites it is mentioned to use UTF8stringEncoding. Which is the the right NSString to string conversion?

Answer

Jacob Relkin picture Jacob Relkin · Oct 26, 2010

Use UTF8String:

fopen([filePath UTF8String], "r");