Go4Expert

Go4Expert (http://www.go4expert.com/)
-   C (http://www.go4expert.com/forums/c/)
-   -   multi byte to wide char converting problem(Related to Unicode) (http://www.go4expert.com/forums/multi-byte-wide-char-converting-related-t6772/)

harimagic 10Oct2007 19:41

multi byte to wide char converting problem(Related to Unicode)
 
Hi,

I prepared this program please go through it. i am running this program in linux with gcc compiler. i am giving input in the tmp.txt file with Telugu or Hindi characters.

But I am not getting proper output. I found 2 problems:
1. These characters are not converting to wide characters.
2. On the console characters are printing with some junk value.

Can any one help me to solve.

PHP Code:

#include<stdio.h>
#include<wchar.h>

void convertMultiBytes(wchar_t *wcharchar *mbyte);

main()
{
FILE *fp;
wchar_t *aa;
char c[100];
int l=0;
if((
fp=fopen("tmp.txt""r")) == NULL) {
    
printf("Cannot open file.\n");
    exit(
1);
  }
fgets(c,25,fp);
l=strlen(c);
printf("%d",l);
aa=(wchar_t *)malloc((l+1)*4);
memset (aa0, (1)*4);
convertMultiBytes(aa,c);
printf("Entered maultybyte string:%s\nConveted wild char string:%ls\n",c,aa);
}


void convertMultiBytes(wchar_t *wcharchar *mbyte)
{
   
int n;
   
char *end,*start;
   
strlen(mbyte) + 1;
   
/* convert multibyte string to wide character string */
   
if (mbstowcs(wchar,mbyte,n) == (size_t)-1)
   {
       
printf("ERROR: Could not convert multibyte character to wide char code\n");
       
convertBytebyByte(wchar,mbyte,n);
   }
}
void convertBytebyByte(wchar_t *wcharchar *mbyteint n)
{
   
int mbcnt;
   
char *end,*start;
   
end mbyte n;
   
start mbyte;

   for(;
start <= end;)
   {
       
mbcnt mbtowc(wchar,start,20);
       if(
mbcnt 0)
       {
           
start += mbcnt;
           
wchar++;
       }
       else
       {
           
printf("Invalid multibyte character occured\n");
           
printf("Converting the invalid character to '?'\n");
           *
wchar '?';
           
start++;
       }
   }



shabbir 10Oct2007 21:24

Re: multi byte to wide char converting problem(Related to Unicode)
 
The second one which is again duplicate of multi byte to wide char converting problem(Related to Unicode). Please do not have the same thread over and over again. It irritates others which in turn reduces the chances of getting any positive response.


All times are GMT +5.5. The time now is 15:14.