This is my code:
#include <stdio.h>
#include <string.h>
#include <iconv.h>
int main()
{
char input[BUFSIZ];
char output[BUFSIZ];
size_t insize = BUFSIZ;
size_t outsize = BUFSIZ;
char **inp = (char **)input;
char **outp = (char **)output;
iconv_t cd = iconv_open("gb2312", "utf-8");
memset(input, '\0', sizeof(input));
memset(output, '\0', sizeof(output));
// freopen("input", "r", stdin);
scanf("%s", input);
insize = strlen(input);
iconv(cd, inp, &insize, outp, &outsize);
printf("%s\n", output);
iconv_close(cd);
return 0;
}
when I run it, I got this message:
a.out:
**gconv.c:75: __gconv: Assertion**
`outbuf != ((void *)0) && *outbuf != ((void *)0)’ failed.
*已放弃*
I can’t found any problem and I feel helpless~ I’m not good at english
Your fourth argument looks wrong. The casting is a good clue that something weird/confused is going on.
You need to pass it a pointer to a pointer, you are passing it a pointer to a character array cast to a pointer to a pointer. That’s not the same thing.
You probably need:
Then call it with
&outpas the fourth argument.