Chapter 9. Internal Processing and File I/O
76
setlocale(LC_ALL, "");
while(1) {
c = getwchar();
if (c == WEOF) break;
putwchar(c);
}
}
I think you can easily imagine a corresponding version using
char
. Since this software does not
do any character manipulation, you can use ordinal
char
for this software.
There are a few points. At first, never forget to call
setlocale()
. Then,
putwchar()
,
getwchar()
,
and
WEOF
are the replacements of
putchar()
,
getchar()
, and
EOF
, respectively. Use
wint_t
instead of
int
for
getwchar()
.
9.2 Character Classification
Here is an example of character clasification using
wchar_t
. At first, this is a non internationalized
version.
/*
*
wc.c
*
*
Word Counter
*
*/
#include 
#include 
int main(int argc, char **argv)
{
int n, p=0, d=0, c=0, w=0, l=0;
while ((n=getchar()) != EOF) {
c++;
if (isdigit(n)) d++;
if (strchr(" \t\n", n)) w++;
if (n == '\n') l++;
}






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