我有以下工作正常的代码:
//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);
最佳答案
您需要将数据复制到缓冲区:
//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.