473,394 Members | 1,714 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,394 software developers and data experts.

printf for french chars

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
9 3908
<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 bévue
Sep 27 '06 #2
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
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
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 bévue
Sep 27 '06 #5
Une bévue 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
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
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 bévue
Sep 27 '06 #8
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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

38
by: Haines Brown | last post by:
I'm having trouble finding the character entity for the French abbreviation for "number" (capital N followed by a small supercript o, period). My references are not listing it. Where would I...
5
by: uli | last post by:
Hi all! I'm posting to both newsgroups, because it's actually a C++ problem but could be that some of you using Matlab-&-MEX-&-C++ was struggling with the same problem. I'm trying to rewrite...
38
by: Xah Lee | last post by:
sometimes i wish to add white space in <p> as to achived effects similar to tab. what should i do? using empty image seems the sure way but rather complicated. (and dosen't change size with...
3
by: buzzdee | last post by:
hi, i just wanted to print out some unsigned long int values in hexadecimal, printing out one value works, but not byte by byte. anybody has a suggestinon what my problem is? this is my...
8
by: aditya | last post by:
hi, Can anybody please tell me that how the following printf(...) statement works- main(){ int d=9; printf("%d",printf("%d")); return 0;
0
by: enrico.leuzzi | last post by:
Hi, sorry for the newbie question but I'm not able to store chinese characters into a column in a table.... how should the db setted and the table created to be able to store different chars...
2
by: ngrover | last post by:
When accessing strings from a french language utf-8 .txt file (that has been resgen'ed into a .resources file) via ResourceManager.GetString() method, I am encountering a problem. All the special...
16
by: Gernot Frisch | last post by:
Hi, class MyString { char* m_data; public: MyString(const char* c) { m_data = new char; strcpy(m_data, c);
10
by: laikon | last post by:
Hello, everyone: this is about overflow in C and C++. int c = 400; printf("%c", c); it print ? on screen, and ascii of '?' is 63.
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.