Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
| From | Nobody <nobody@nowhere.com> |
|---|---|
| Subject | Re: fgetwc doesn't read Unicode |
| Date | 2011-06-09 02:39 +0100 |
| Message-Id | <pan.2011.06.09.01.39.26.485000@nowhere.com> |
| Newsgroups | comp.lang.c |
| References | <isnn5i$cuu$1@news.onet.pl> |
| Organization | Zen Internet |
On Wed, 08 Jun 2011 13:41:37 +0200, felix.leg wrote:
> I wrote a simple code to test unicode reading in C:
> while( (chrk = fgetwc(f)) != WEOF ) {
fgetwc() assumes that the file is in the locale's encoding. If the file
is in e.g. UTF-8, then you need to use a UTF-8 locale. This means
calling setlocale(LC_CTYPE, ...); if you use "" as the locale, then the
appropriate environment variables need to indicate a UTF-8 locale.
> wprintf(L"%C ,", chrk );
> }
> printf("\b.\n"); //#1
> (it looks like the #1 line wasn't executed too)
You can't mix wide and byte I/O on a stream. A stream starts out
unoriented; the first operation on a stream sets the orientation (so
the wprintf() call will make stdout wide-oriented). Once a stream has an
orientation, the orientation can't be changed[1], and operations which
require a different orientation (e.g. printf on a wide-oriented stream)
aren't permitted.
[1] You can, however, create a new stream with freopen(), which returns
an unoriented stream.
> It stops after fgetwc reach the first non-ASCII character from file. I
> thought this function was *supposed to* read them...WTF?
At startup, all locale categories default to "C" (which has ASCII as its
encoding). You have to call setlocale() to change it.
Back to comp.lang.c | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
fgetwc doesn't read Unicode "felix.leg" <felix.leg@vp.pl> - 2011-06-08 13:41 +0200
Re: fgetwc doesn't read Unicode jt@toerring.de (Jens Thoms Toerring) - 2011-06-08 20:18 +0000
Re: fgetwc doesn't read Unicode Nobody <nobody@nowhere.com> - 2011-06-09 02:39 +0100
Re: fgetwc doesn't read Unicode "felix.leg" <felix.leg@vp.pl> - 2011-06-12 11:30 +0200
Re: fgetwc doesn't read Unicode Nobody <nobody@nowhere.com> - 2011-06-13 02:09 +0100
Re: fgetwc doesn't read Unicode jt@toerring.de (Jens Thoms Toerring) - 2011-06-13 21:38 +0000
Re: fgetwc doesn't read Unicode Dirk Krause <devnull@fh-schmalkalden.de> - 2011-06-09 13:19 +0000
csiph-web