hi guys, I'm new with Objective C.
I would like to know why this code does not work fine. The idea is to make a function that copies the content of a NSString into a Cstring.
I send a message to setAttr, i.e: [ self setAttr:@"something"]
- (BOOL) setAttr:(NSString *) src{
const char *dst;
[ self NSString2CString: src dst: dst ];
printf("%s",dst); // <-- gives me junk
return YES;
}
- (BOOL) NSString2CString: (NSString *) src dst: (const char *) dst {
const char * __src= [src UTF8String];
if ( (dst=(const char *) malloc( strlen(__src)+ 1) ) == NULL) return NO;
strcpy(dst, __src);
return YES;
}
thanks