Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Convert a CFStringRef to a C string?

Hello lovely computer people:

I would like to convert the following CFStringRef into a CString. Any idea how?

recordFilePath = (CFStringRef)[NSTemporaryDirectory() stringByAppendingPathComponent: @"recordedFile.wav"];

Thanks!


EDIT 1

DarkDust answer seems to come close, but I'm still getting an error (see comment). Any help?

like image 518
Eric Brotto Avatar asked Feb 10 '11 17:02

Eric Brotto


2 Answers

A straightforward solution:

CFStringGetCString(myCFStringRef, myCStringPointer, mySize, myEncoding);

Checkout this function:

Boolean CFStringGetCString (
   CFStringRef theString,
   char *buffer,
   CFIndex bufferSize,
   CFStringEncoding encoding
);
like image 117
Vikram Singh Avatar answered Nov 07 '22 15:11

Vikram Singh


Since a CFStringRef can be toll-free casted to NSString, you can simply do:

myCString = [(NSString *)myCFStringRef UTF8String];

or in your case:

myCString = [[NSTemporaryDirectory() stringByAppendingPathComponent: @"recordedFile.wav"] UTF8String];
like image 7
DarkDust Avatar answered Nov 07 '22 16:11

DarkDust