I'm trying to convert ASCII to hex. Here's my function.
NSString *asciiToHex(NSString *input) {
NSUInteger inputLength = [input length];
unichar *chars = malloc(inputLength * sizeof(unichar));
[input getCharacters:chars];
NSMutableString *hexString = [[NSMutableString alloc] init];
for (NSUInteger i = 0; i < inputLength; i++) {
[hexString appendFormat:@"%02x", chars[i]];
}
return hexString;
}
It works in xcode but if I try to compile it in a theos project I get this error
error: cannot initialize a variable of type 'UInt8 *'
(aka 'unsigned char *') with an rvalue of type 'void *'
UInt8 *outBytes = malloc(sizeof(UInt8) * ((inLength / 2) + 1));
^
How can I get theos to compile it or how do I rewrite the function?
malloc returns a pointer of type void*
. Typecast rsvalue to unichar as follows
unichar *chars = (unichar*)malloc(inputLength * sizeof(unichar));