将char *转换为char&

时间:2013-10-10 10:55:58

标签: c char base64 const

我有以下代码正常工作:

//function1 for decoding base64
int base64_decode (const char *base64, char *to) { /*function*/ }

//code which is working
buf_struct tmpbuf;//structure
base64_decode(buffer, (char *)&tmpbuf);

我希望将其转换为避免其他功能做同样的事情,进入:

//function2 for decoding base64
char *unbase64(unsigned char *input, int length) { /*function*/ }

//code needs to be modified
buf_struct tmpbuf;//structure
char *unbase = unbase64(buffer, strlen(buffer));
unbase = (char *)&tmpbuf;

但第二个不起作用。

* 如何将“char *”转换为“(char )&” ?

编辑:

char *unbase;
unbase = malloc(strlen(buffer) + 1);
memset(unbase, 0, strlen(buffer) + 1);
//unbase = unbase64(buffer, strlen(buffer));
base64_decode(buffer, unbase);
fprintf(stderr,"unbase: %s\n",unbase);
strcpy((char *)&tmpbuf, unbase);

1 个答案:

答案 0 :(得分:1)

您需要将数据复制到缓冲区:

//code needs to be modified
buf_struct tmpbuf;//structure
char *unbase = unbase64(buffer, strlen(buffer));
strcpy((char *)&tmpbuf, unbase);

// Depending on the contract for unbase64 you may need to free() unbase here.