This is an issue with console applications running only on Windows
environments where ANSI code page is not equal to OEM code page.
1. When strings or characters are printed to MSDOS console the
characters are interpreted using OEM code page.
2. Command line arguments passed to program are encoded using ANSI code
page in argv[].
Now for most european language installations of Windows, ANSI and OEM
code pages differ for a running application. So the characters when
printed to console are interpreted wrongly.
Solution to this problem is to convert to OEM string just before
displaying.
#include <stdio.h>
#include <locale.h>
int main(int argc, char **argv)
{
char correctDisplay[1024];
if (argc 1)
{
printf("%s\n", argv[1]);
strcpy((char*)correctDisplay, argv[1]);
CharToOem((const char*)correctDisplay, (char*)array); /* MUST for
correct display of extended chars */
printf("correctDisplay = %s\n", correctDisplay);
}
return 0;
}
Note that this issue is reproducible for extended chars in english
language as well.
For more info see
http://blogs.msdn.com/michkap/archiv...08/369197.aspx
regards,
Kaustubh
Jack Klein wrote:
On 27 Sep 2006 00:27:39 -0700, ka**********@gmail.com wrote in
comp.lang.c:
I am facing issues printing french chars like [ é ] using printf
function.
I have reproduced this issue with simple C program as follows.
#include <stdio.h>
#include <locale.h>
int main(int argc, char **argv)
{
if (argc 1)
{
printf("%s\n", argv[1]);
}
return 0;
}
execute this prog from dos prompt passing string say "abc_éèçàù"
where chars following '_' are french chars.
I get a garbled output on command promt. Where as if I debug this
prog(using MS studio), I can see that argv[1] has the proper string.
additional info:
1default console page is 850
2Running Windows in french locale.
Does any body why does it happens.
I see a lot of replies that trail off into nothing useful.
You are asking in the wrong place. The C language defines nothing at
all about the glyphs (visual symbols) that appear when characters are
sent to any device. This is completely a Windows issue.
Ask in a Windows group.
--
Jack Klein
Home: http://JK-Technology.Com
FAQs for
comp.lang.c http://c-faq.com/
comp.lang.c++ http://www.parashift.com/c++-faq-lite/
alt.comp.lang.learn.c-c++
http://www.contrib.andrew.cmu.edu/~a...FAQ-acllc.html