Chapter 9. Internal Processing and File I/O
81
/* extract i.c
*
* a sample program to extract each character contained in the string
* INTERNATIONALIZED
*/
#include 
#include 
#include 
#include 
int main(int argc, char **argv)
{
wchar_t *wp;
char p[MB_CUR_MAX+1];
int c, n, len;
/* Don't forget. */
setlocale(LC_ALL, "");
if (argc < 2) {
printf("Usage: %s [string]\n", argv[0]);
return 0;
}
printf("Your string is: \"%s\".\n", argv[1]);
/* To obtain each character of the string, it is easy to convert */
/* the string into wide string and re convert each of the wide */
/* string into multibyte characters. */
n = strlen(argv[1]) * sizeof(wchar_t);
wp = (wchar_t *)malloc(n);
len = mbstowcs(wp, argv[1], n);
for (c=0; c
/* re convert from wide character to multibyte character */
int x;
x = wctomb(p, wp[c]);
/* One multibyte character may be two or more bytes. */
/* Thus "%s" is used instead of "%c". */
if (x>0) p[x]=0;
printf("Character #%d is \"%s\" (%d byte(s)) \n", c, p, x);
}






footer




 

 

 

 

 Home | About Us | Network | Services | Support | FAQ | Control Panel | Order Online | Sitemap | Contact

indiana web hosting

 

Our partners: PHP: Hypertext Preprocessor Best Web Hosting Java Web Hosting Inexpensive Web Hosting  Jsp Web Hosting

Cheapest Web Hosting Jsp Hosting Cheap Hosting

Visionwebhosting.net Business web hosting division of Web Design Plus. All rights reserved