// test_base64.c
#include <stdio.h>
#include <stdlib.h>
#include <locale.h>
#include <glib.h>
int main(void) {
setlocale(LC_ALL,"");
gchar* text = g_strdup("中文");
gchar* result = NULL;
guchar* result2 = NULL;
gsize length = 0;
result = g_base64_encode(text, strlen(text));
g_print("%s\n", result);
result2 = g_base64_decode(result, &length);
g_print("%s\n", result2);
g_free(text);
g_free(result);
g_free(result2);
return EXIT_SUCCESS;
}
/*
$ gcc `pkg-config --cflags --libs glib-2.0` -o test_base64 test_base64.c
$ ./test_base64
5Lit5paH
中文
*/
沒有留言:
張貼留言