473,545 Members | 1,558 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 10983
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
25899
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
4281
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
2298
by: François 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
2767
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
3159
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
55845
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
3266
by: Tomás | 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
12428
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
5688
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
7467
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
0
7756
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
5971
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 project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
1
5326
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
4944
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
3450
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...
0
3442
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
1879
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
703
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.