我有工作了下面的代碼罰款:轉換的char *爲char&
//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);
在你這是從'tmpbuf'期待第二種情況?你在函數'unbase64'中做什麼? 'unbase'是通過返回'unbase64'來分配的,那麼你在下一行再次分配什麼? –
我認爲你想這樣做:'tmpbuf-> .. = unbase;'。在第一個例子中,你可能不應該把'tmpbuf'強制轉換爲'char *',而是使用'struct'的成員,它的定義是什麼? – Kninnug