我已經編寫了一個示例代碼,遵循link使用iconv將ASCII轉換爲UTF-16LE,但輸出只顯示了一個單一的文字和空格。代碼附在下面,請讓我知道我要去哪裏錯了。從ASCII到utf-16LE的轉換給出了問題
#include <iconv.h>
#include <stdio.h>
#include <string.h>
int main()
{
char Input[20];
char Output[100];
size_t insize,out_size;
memset(Input,0,sizeof(Input));
memset(Output,0,sizeof(Output));
int nconv=0;
char *Inptr;
char *outptr;
printf("Input data :");
scanf("%s",Input);
iconv_t cd = iconv_open("UTF-16LE","ASCII");
if(cd==(iconv_t)-1)
{
printf("iconv_open has failed ");
return 0;
}
insize=strlen(Input);
out_size=3*insize;
Inptr =Input;
outptr=(char *)Output;
nconv=iconv(cd,&Inptr,&insize,&outptr,&out_size);
if(nconv!=0)
{
printf("Unable to perform conversion ");
return 0;
}
printf("\n Data After conversion from ASCII to UTF-16 = %s \n ",Output);
}
對於相同的輸出如下
輸入數據給出:你好世界
數據從ASCII轉換爲UTF-16 = H後