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

Home Posts Topics Members FAQ

how to initial and print the unicode character?

i want to try ANSI C99's unicode fuctions. so i write a test program.
the function is simple, but i cannot compile it with dev c++ 4.9.9.2
under windows xp sp2, since the compiler always think that the
initialization of the wchar_t string is illegal. here is my function:
#include <stdio.h>
#include <stdlib.h>
#include <wchar.h>
#include <wctype.h>
#include <string.h>

int main(int argc, char *argv[])
{
wchar_t *cur_buff=L"X";
wprintf(cur_buf f);
return 0;
}

in the function, the initialization of wchar_t *cur_buff is L"X", if X
is an ascii character, then all things function well. But if X is
non-ascii charater such as a Chinese character, compiler would alert
that this is a illegal byte sequence. The source file is saved as ascci
code, and the character set is gb2312. i wonder why this happens?

Jul 4 '06 #1
15 10994
On 2006-07-04, wizardyhnr <wi********@gma il.comwrote:
i want to try ANSI C99's unicode fuctions. so i write a test program.
the function is simple, but i cannot compile it with dev c++ 4.9.9.2
under windows xp sp2, since the compiler always think that the
initialization of the wchar_t string is illegal. here is my function:
Without looking at your actual problem, here's a few tips:
1) It's fairly unlikely that you actually have a C99 compiler.
2) It's very unlikely that something with the word "C++" in it
is even a C compiler, let alone a C99 compiler.

Other than that, we don't care what OS or platform you have. We discuss
standard C here, and that's platform independant.

--
Andrew Poelstra <http://www.wpsoftware. net/blog>
To email me, use "apoelstra" at the above address.
"You people hate mathematics." -- James Harris
Jul 4 '06 #2
* wizardyhnr:
i want to try ANSI C99's unicode fuctions. so i write a test program.
the function is simple, but i cannot compile it with dev c++ 4.9.9.2
under windows xp sp2, since the compiler always think that the
initialization of the wchar_t string is illegal. here is my function:
#include <stdio.h>
#include <stdlib.h>
#include <wchar.h>
#include <wctype.h>
#include <string.h>

int main(int argc, char *argv[])
{
wchar_t *cur_buff=L"X";
wprintf(cur_buf f);
return 0;
}

in the function, the initialization of wchar_t *cur_buff is L"X", if X
is an ascii character, then all things function well. But if X is
non-ascii charater such as a Chinese character, compiler would alert
that this is a illegal byte sequence. The source file is saved as ascci
code, and the character set is gb2312. i wonder why this happens?
Don't know about C, but in C++ you'd have to put a 'const' in there,

wchar_t const* curr_buff = L"X";

--
A: Because it messes up the order in which people normally read text.
Q: Why is it such a bad thing?
A: Top-posting.
Q: What is the most annoying thing on usenet and in e-mail?
Jul 4 '06 #3
"Alf P. Steinbach" <al***@start.no writes:
* wizardyhnr:
> wchar_t *cur_buff=L"X";

Don't know about C, but in C++ you'd have to put a 'const' in there,
wchar_t const* curr_buff = L"X";
Not in C.
--
"It wouldn't be a new C standard if it didn't give a
new meaning to the word `static'."
--Peter Seebach on C99
Jul 4 '06 #4
* Ben Pfaff:
"Alf P. Steinbach" <al***@start.no writes:
>* wizardyhnr:
>> wchar_t *cur_buff=L"X";
Don't know about C, but in C++ you'd have to put a 'const' in there,
wchar_t const* curr_buff = L"X";

Not in C.
On second thought, perhaps not in C++ either (sorry for being a bit
fast). Haven't checked, and since this is a C newsgroup, won't do. The
C++ non-const possibility for char* is just for C compatibility.

--
A: Because it messes up the order in which people normally read text.
Q: Why is it such a bad thing?
A: Top-posting.
Q: What is the most annoying thing on usenet and in e-mail?
Jul 4 '06 #5
wizardyhnr said:
i want to try ANSI C99's unicode [functions].
Unicode is not mentioned even once in my copy of the C99 Standard. On the
other hand, wide characters /are/ so mentioned, so let's assume you meant
that.

<snip>
in the function, the initialization of wchar_t *cur_buff is L"X", if X
is an ascii character, then all things function well. But if X is
non-ascii charater such as a Chinese character, compiler would alert
that this is a illegal byte sequence.
As long as the compiler (or, almost certainly, the preprocessor in this
case) supports the basic source character set, it remains within its rights
to reject any other characters it encounters within the source code.

You can, however, read information into a wchar_t from a file at run-time. I
suggest you explore that option.

--
Richard Heathfield
"Usenet is a strange place" - dmr 29/7/1999
http://www.cpax.org.uk
email: rjh at above domain (but drop the www, obviously)
Jul 4 '06 #6
Richard Heathfield wrote:
wizardyhnr said:
i want to try ANSI C99's unicode [functions].

Unicode is not mentioned even once in my copy of the C99 Standard. On the
other hand, wide characters /are/ so mentioned, so let's assume you meant
that.
Unicode is explicitly mentioned in TC2 in the description for
__STDC_ISO_1064 6__, and while the wording before TC2 does not mention
"Unicode", the differences between Unicode and ISO 10646 are not
relevant here.

#ifndef __STDC_ISO_1064 6__
#error
#endif
/* Now, the assumption that C's wide character functions are Unicode
functions is valid */

Also, the \U and \u escape sequences work with Unicode / ISO 10646
character values.

Jul 4 '06 #7
Andrew Poelstra <ap*******@loca lhost.localdoma inwrote:
On 2006-07-04, wizardyhnr <wi********@gma il.comwrote:
i want to try ANSI C99's unicode fuctions. so i write a test program.
the function is simple, but i cannot compile it with dev c++ 4.9.9.2
under windows xp sp2, since the compiler always think that the
initialization of the wchar_t string is illegal. here is my function:

Without looking at your actual problem, here's a few tips:
0) It's ISO C99, and has been from the start.
1) It's fairly unlikely that you actually have a C99 compiler.
It's actually 100% sure he hasn't.
2) It's very unlikely that something with the word "C++" in it
is even a C compiler, let alone a C99 compiler.
It's actually 100% sure it is an IDE with compiler suite which provides
C++, C89, and a Win32 library (MingW, to be precise), but not C99.

Richard
Jul 4 '06 #8
wizardyhnr wrote:
i want to try ANSI C99's unicode fuctions. so i write a test program.
the function is simple, but i cannot compile it with dev c++ 4.9.9.2
under windows xp sp2, since the compiler always think that the
initialization of the wchar_t string is illegal. here is my function:
[snip code]

I'm only guessing but I think the source character set of your compiler
doesn't support characters other than the basic C character set.

Maybe the following URLs could shed some light in this obscure area?
<http://evanjones.ca/unicode-in-c.html>
<http://www.cl.cam.ac.u k/~mgk25/unicode.html>
<http://www.tbray.org/ongoing/When/200x/2003/04/26/UTF>

Also the authoritative resource:
<http://www.unicode.org/>

Jul 4 '06 #9
wizardyhnr wrote:
i want to try ANSI C99's unicode fuctions.
[snip]

The following leans towards Linux, it's still a good introduction to
Unicode and C's support for it by means of the wchar_t type and
standard library functions.

<http://www-128.ibm.com/developerworks/linux/library/l-linuni.html>

Jul 4 '06 #10

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

23
25906
by: Hallvard B Furuseth | last post by:
Has someone got a Python routine or module which converts Unicode strings to lowercase (or uppercase)? What I actually need to do is to compare a number of strings in a case-insensitive manner, so I assume it's simplest to convert to lower/upper first. Possibly all strings will be from the latin-1 character set, so I could convert to...
4
4291
by: Joerg Lehmann | last post by:
I am using Python 2.2.3 (Fedora Core 1). The problem is, that strings containing umlauts do not work as I would expect. Here is my example: >>> a = '' >>> b = '123' >>> print "%-5s %-5s\n%-5s %-5s" % (a,a,b,b) 123 123 I would expect, that the displayed width of a or b is the same: 5 characters.
9
2301
by: Franois Pinard | last post by:
Hi, people. I hope someone would like to enlighten me. For any application handling Unicode internally, I'm usually careful at properly converting those Unicode strings into 8-bit strings before writing them out. However, this morning, I mistakenly forgot to do so before using one Unicode string (containing a non-ASCII character) as an...
6
2774
by: S. | last post by:
if in my website i am using the sgml { notation, is it accurate to say to my users that the site uses unicode or that it requires unicode? is there a mathematical formula to calculate a unicode value given its utf8 value? Rgds, Sam
4
3160
by: Basil | last post by:
Hello. I have compiler BC Builder 6.0. I have an example: #include <strstrea.h> int main () { wchar_t ff = {' s','d ', 'f', 'g', 't'};
10
55868
by: Amuro | last post by:
I want to print a string value that represent temperature. how to print the 'little superscript circle' in C#? thx...
13
3280
by: Toms | last post by:
Let's start off with: class Nation { public: virtual const char* GetName() const = 0; } class Norway : public Nation { public: virtual const char* GetName() const
8
12436
by: =?gb2312?B?yMvR1MLkyNXKx8zs0cSjrM37vKvM7NHEsru8+7z | last post by:
I lookup the utf-8 form of delta from the link. http://www.fileformat.info/info/unicode/char/0394/index.htm and then I want to print it in the python ( I work under windows) #!/usr/bin/python #coding=utf-8 print "\xce\x94"
7
5692
by: =?gb2312?B?yMvR1MLkyNXKx8zs0cSjrM37vKvM7NHEsru8+7z | last post by:
Who could explain the follow issue ? Traceback (most recent call last): File "<stdin>", line 1, in <module> UnicodeEncodeError: 'gbk' codec can't encode character u'\x80' in position 0: il legal multibyte sequence or I just put the unicode number
0
8153
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
8309
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
7902
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
8178
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...
1
5679
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupr who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
0
3806
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
1
2304
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
1
1405
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
1141
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.