473,581 Members | 2,744 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 3936
<ka**********@g mail.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
ka**********@gm ail.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**********@gm ail.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**********@i nvalid.invalidw rote:
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
Une bvue wrote:
Michael Mair <Mi**********@i nvalid.invalidw rote:
>>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_AL L, "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**********@gm ail.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**********@i nvalid.invalidw rote:
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_AL L, "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
On 27 Sep 2006 00:27:39 -0700, ka**********@gm ail.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.l earn.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*)c orrectDisplay, argv[1]);
CharToOem((cons t char*)correctDi splay, (char*)array); /* MUST for
correct display of extended chars */
printf("correct Display = %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**********@gm ail.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.l earn.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
5714
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 find an answer to this question (don't find it in the W3C_char_entities document). -- Haines Brown brownh@hartford-hwp.com
5
6250
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 some Matlab routines in C++ for reusing them identically in Matlab and some other simulation tools. For computational algebra I want to use the Matrix...
38
23965
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 font) Woudl some of the space character in unicode work? (my html files uses unicode) Xah
3
2286
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 program:
8
2701
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
3223
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 like chinese, french, italian and english ? thanks in advance,
2
2925
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 characters are not coming through. The accented vowels etc. are being stripped out. Other non-latin languages are working just fine, the utf-8...
16
2767
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
3953
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
8134
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
0
8296
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
1
7880
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
0
8157
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
0
6539
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development projectplanning, coding, testing, and deploymentwithout human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
0
5350
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
0
3807
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2295
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
0
1119
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

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.