I'm a c-noob if it comes to strings hand converting back and forth from objective-c and c itself. I want to convert a string to a mp_int and back. The library i'm using is libtommath and the method signatures are below.
mp_int a;
mp_init(&a);
int res = mp_read_radix(&a, "3493483984238472398423742344793247923648234", 10);
NSLog(@"%i", res);
unsigned char *b = malloc(255);
mp_toradix(&a, &b, 10);
NSString *c = [[NSString alloc] initWithCString:b encoding:NSASCIIStringEncoding];
NSLog(@"--%@", c);
Method signatures:
int mp_init (mp_int * a)
int mp_read_radix (mp_int * a, const char *str, int radix)
int mp_toradix (mp_int * a, char *str, int radix)
The code above seems to be bonkers ... can anyone help? It gives a EXC_BAD_ACCESS at the end of the function call (close bracket).
Mark