2016-10-05 54 views
0

我有一个base 64编码的字符串,我想解码。 它看起来像这样:Base 64 decode在C中返回NULL

VGhpcyBpcyBhIGZpbGUgdGhhdCBJIHdhbnQgdG8gZGVjb2Rl 

当我做..

gsize *out_len; 
unsigned const char *decoded; 
decoded = g_base_64_decode(myString, out_len); 

,并打印出我的解码的字符串,我得到空也,我得到的断言: '!out_len = NULL' 失败来自Glib

这是怎么发生的?如何使用此功能正确解码我的字符串? https://developer.gnome.org/glib/stable/glib-Base64-Encoding.html#g-base64-decode-step

+3

您是否为'out_len'分配了内存? – Barmar

+1

'out_len'点无处。更换'gsize * out_len;'和'gsize out_len;'和'g_base_64_decode(MyString的,out_len);'和'g_base_64_decode(MyString的,与out_len);' –

+0

@squeamishossifrage:发表它的一个答案! –

回答

2

out_len参数是输出参数。这意味着您通常堆栈这样上创建gsize类型的out_len变量:

gsize out_len; 

,然后调用函数传递指针上述变量(即传递的的地址它:&out_len),例如:

decoded = g_base_64_decode(myString, &out_len);