The essence of what I'm trying to accomplish is the following. I want to pass in an address of integer (integer pointer) which is in form of a string to a function expecting an integer pointer as an argument. In terms of simple code, I want to do the following:
void dsp(int *);
int main() {
char *b;
int a=2;p=&a;
b = (char *)malloc(100*sizeof(char));
sprintf(b, "%p",p);
puts( b );
dsp(&a);
dsp((int *)strtol(b,16));
free(b);
return 0;
}
void dsp(int *addr)
{
printf("val:%d\n",*addr);
}
And this is what my output is:
0x7fbffffa6c (from puts(b))
val:2
Segmentation fault
Can anybody suggest what is wrong with above and/or how to go about it? Any help would be appreciated. Thank you.