Get Paid for Working on Projects Matching Your Expertise at Go4Expert's Jobs Board
Go4Expert
Go4Expert RSS Feed

Go Back   Programming and SEO Forum >  Go4Expert > Queries and Discussion > Programming > C-C++

Closed Thread  Copy HTML to Clipboard  Copy BBCode to Clipboard  | More
 
Bookmarks Thread Tools Search this Thread Display Modes
Old 10-10-2007, 07:41 PM   #1
Go4Expert Member
 
Join Date: Oct 2007
Posts: 21
Thanks: 0
Thanked 0 Times in 0 Posts
Rep Power: 0
harimagic is on a distinguished road
Red face

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++;
       }
   }

harimagic is offline  
Old 10-10-2007, 09:24 PM   #2
Go4Expert Founder
 
shabbir's Avatar
 
Join Date: Jul 2004
Location: On Earth
Posts: 12,750
Thanks: 131
Thanked 294 Times in 228 Posts
Rep Power: 10
shabbir has much to be proud ofshabbir has much to be proud ofshabbir has much to be proud ofshabbir has much to be proud ofshabbir has much to be proud ofshabbir has much to be proud ofshabbir has much to be proud ofshabbir has much to be proud of
Send a message via Yahoo to shabbir

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.
shabbir is offline  
Closed Thread  Copy HTML to Clipboard  Copy BBCode to Clipboard  | More


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes
Bookmarks

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off

 

All times are GMT +5.5. The time now is 04:13 PM.