c - Base 64解码在C中返回NULL

标签 c base64 decode glib

我有一个要解码的 base 64 编码字符串。 它看起来像这样:

VGhpcyBpcyBhIGZpbGUgdGhhdCBJIHdhbnQgdG8gZGVjb2Rl

当我这样做的时候..

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

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

为什么会这样?如何使用此函数正确解码我的字符串? https://developer.gnome.org/glib/stable/glib-Base64-Encoding.html#g-base64-decode-step

最佳答案

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

gsize out_len;

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

decoded = g_base_64_decode(myString, &out_len);

关于c - Base 64解码在C中返回NULL,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39878788/

相关文章:

宏可以用来模拟 C++ 模板函数吗?

java - 对文件进行Base64编码并压缩

php - 将base64转换为php音频文件中的声音文件

javascript - ActionScript2 Base64 编码/解码二进制数据

perl - 当我不知道字节顺序时,如何在 Perl 中解码 UTF-16 数据?

c - leetcode#24 Swap Nodes in Pairs 运行时错误(C语言)

c - 制作队列程序

batch-file - 如何使用管道解码我的 tiff 图片以输入 tensorflow?

c - 用于删除 C 代码中所有循环的工具

php - 我将如何读取此数组 ("stdClass Object")