By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
446,332 Members | 1,404 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 446,332 IT Pros & Developers. It's quick & easy.

printf for french chars

P: n/a
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.

Sep 27 '06 #1
Share this Question
Share on Google+
9 Replies


P: n/a
<ka**********@gmail.comwrote:
#include <stdio.h>
#include <locale.h>

int main(int argc, char **argv)
{
if (argc 1)
{
printf("%s\n", argv[1]);
}
return 0;
}
no prob on macos x :

~/work/C/essais/locale%ycc test french.c
~/work/C/essais/locale%./test

~/work/C/essais/locale%>
--
une bvue
Sep 27 '06 #2

P: n/a
ka**********@gmail.com wrote:
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.
Why did you not set the locale for your C programme?
You start in the "C" locale where you are only guaranteed to have
access to the characters from the source character set.
Try setting the locale using setlocale().

Cheers
Michael
--
E-Mail: Mine is an /at/ gmx /dot/ de address.
Sep 27 '06 #3

P: n/a
I had had a go at setting locale.
but the question is, input to program from console seems to work as
argv has a valid string in it. point to note is tht these chars are
from code page 850 which is default.
The only issue is in displaying it on console.

thanks,
kaustubh

Michael Mair wrote:
ka**********@gmail.com wrote:
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.

Why did you not set the locale for your C programme?
You start in the "C" locale where you are only guaranteed to have
access to the characters from the source character set.
Try setting the locale using setlocale().

Cheers
Michael
--
E-Mail: Mine is an /at/ gmx /dot/ de address.
Sep 27 '06 #4

P: n/a
Michael Mair <Mi**********@invalid.invalidwrote:
Why did you not set the locale for your C programme?
You start in the "C" locale where you are only guaranteed to have
access to the characters from the source character set.
Try setting the locale using setlocale().
this "locale" isn't an environment variable ?
--
une bvue
Sep 27 '06 #5

P: n/a
Une bvue wrote:
Michael Mair <Mi**********@invalid.invalidwrote:
>>Why did you not set the locale for your C programme?
You start in the "C" locale where you are only guaranteed to have
access to the characters from the source character set.
Try setting the locale using setlocale().

this "locale" isn't an environment variable ?
No; every C programme starts out in the "C" locale, see for example
C99, 7.11.1.1#4
"At program startup, the equivalent of
setlocale(LC_ALL, "C");
is executed."
What the "C" locale encompasses is partially implementation defined,
so you may in theory end up with a locale which "cannot even print
'$'", let alone accented characters.

Cheers
Michael
--
E-Mail: Mine is an /at/ gmx /dot/ de address.
Sep 27 '06 #6

P: n/a
Please do not top-post.

ka**********@gmail.com wrote:
Michael Mair wrote:
>>ka**********@gmail.com wrote:
>>>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.

Why did you not set the locale for your C programme?
You start in the "C" locale where you are only guaranteed to have
access to the characters from the source character set.
Try setting the locale using setlocale().

I had had a go at setting locale.
With which effect?
but the question is, input to program from console seems to work as
argv has a valid string in it.
Note that what you see in the debugger is not necessarily what the
programme "sees". The debugger might display character values according
to a "code page" different from the one that the programme uses.
point to note is tht these chars are
from code page 850 which is default.
The only issue is in displaying it on console.
Read my other reply, <4n************@individual.net>.
The initial locale always is "C".
-Michael
--
E-Mail: Mine is an /at/ gmx /dot/ de address.
Sep 27 '06 #7

P: n/a
Michael Mair <Mi**********@invalid.invalidwrote:
No; every C programme starts out in the "C" locale, see for example
C99, 7.11.1.1#4
"At program startup, the equivalent of
setlocale(LC_ALL, "C");
is executed."
What the "C" locale encompasses is partially implementation defined,
so you may in theory end up with a locale which "cannot even print
'$'", let alone accented characters.
OK, thanxs !
--
une bvue
Sep 27 '06 #8

P: n/a
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
Sep 28 '06 #9

P: n/a
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
Oct 12 '06 #10

This discussion thread is closed

Replies have been disabled for this discussion.