Can you show me some example programs demonstrating the use of these functions? (I am a newbie in C++ program)
Say for example, the passage is "abcdefXXXX23" where XXXX are the Chinese characters.
Thanks!
Main Topics
Browse All TopicsHi
I'd like to ask any of you the method of recognizing Chinese character (a multibyte character) in a passage containing both Chinese and some single byte characters, such as English and numbers.
When I use a pointer, it only points the passage byte by byte and it is not able to detect whether it is a multibyte character or not.
Is there a way to:
1. Extract these Chinese characters from the passage OR
2. Intelligently pointing character by character (not matter the character is multibyte or single byte) OR
3. Convert all of them to multibyte characters?
Your suggestions will be much appreciated! Thanks!
This Question has been solved and asker verified All Experts Exchange premium technology solutions are available to subscription members.
Experts Exchange has been collecting answers to technology questions since 1996…3 million and counting! If you have a question, chances are we already have your answer.
If you can't find the exact answer you're looking for, ask our exclusive community of 50,000 experts. You’ll get a personalized answer from a trusted professional.
Thousands of free tech tips, tricks, how-to’s and tutorials are available in our peer reviewed articles section. See for yourself how smart our experts are, no login required.
Access the answers to your technology questions today.
30-day free trial. Register in 60 seconds.
Members of the expert community talk about why the experience at Experts Exchange is different than what you will find anywhere else.

Try it out and discover for yourself.
30-day free trial. Register in 60 seconds.
Join the community of experts here and help other tech pros by answering question in your area of expertise. You can earn FREE access to all Experts Exchange's premium features and resources.
In fact, what I am trying to do is to count the number of occurrence of every character (Chinese character must be counted) appeared in the passage, which consists of different types of characters (ie. English + Chinese + Numbers).
What I can think of is using pointers to do so. However, I have encountered the problem mentioned...... So, I am pondering whether I should convert all the characters in the passage to be double-byte first and then increment the pointer by 2 everytime reading a character, or I should separate the multibyte characters (Chinese) from the singlebyte ones (English + Numbers) and then count them respectively.
Do you have any idea?
Hi,
I think what you can do is:
COnvert all the characters from narrow to wide and do a byte comparison to count number of characters.
Use:
mbstate_t ps;
mbsrtowcs(wchar_t* wide,const char* narrow, int len, mbstate_t* ps);
char* narrow will be your string from passage
and then use code with logic as following... (You wil need to modify it for your own use)
[I can develop the program for you, but 125 is too less for that much work.]
#include <iostream.h>
#include <fstream.h>
int main () {
ifstream f1;
char c;
int numchars, numlines;
f1.open("test");
numchars = 0;
numlines = 0;
f1.get(c);
while (f1) {
while (f1 && c != '\n') {
numchars = numchars + 1;
f1.get(c);
}
numlines = numlines + 1;
f1.get(c);
}
cout << "The file has " << numlines << " lines and "
<< numchars << " characters" << endl;
return(0);
}
Business Accounts
Answer for Membership
by: pb_indiaPosted on 2004-11-01 at 07:53:24ID: 12463933
You can use, depending on your need :
1. wcsrtombcs(wchar_t*, char*, int); //wide to Multibyte
2. _mbbtombc //Convert 1-byte multibyte character to corresponding 2-byte multibyte character