I have a variable of type char[] and I want to copy NSString value in it. How can I convert an NSString to a char array?
We need to play NSString as a character array for working on coding practices which is otherwise much simpler to do in plain C coding. Using characterAtIndex: and appendFormat: helps me. May be this will help.
NSString *str = @"abcdef";
NSMutableString *strResult = [NSMutableString string];
for (NSUInteger i = 0; i < [str length]; i++) {
char ch = [str characterAtIndex:i];
[strResult appendFormat:@"%c", ch];
}
NSLog(@"%@", strResult);