473,836 Members | 1,457 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

how to use unicode in c under linux?

hi all
you know unicdoe is very important, under linux, i always use
utf-8, but now i need save one file in unicode. my linux is centos.
and i know this system support unicode. the wchar_t *p is a unicode
string, i print the len it is 7. it is right,i save the file, the
file length is 7. i had checked it, it is'hello??' ? = 0x3F, so
what's wrong with these code? thank you.
#define __STDC_ISO_1064 6__ 200104L
#include <wchar.h>
#include <stdio.h>
#include <stdlib.h>
#define _TEXT(x) L ## x
int main() {

FILE *fp = NULL;
wchar_t *filename = _TEXT("oov.txt" );
wchar_t *p = _TEXT("hello ");

wprintf(_TEXT(" %S\n"), p);

wprintf(_TEXT(" %d \n"), wcslen(p));

fp = fopen( "oov.txt", "w");
fwprintf(fp, _TEXT("%S"), p);
fclose(fp);
return 0;
}


my locale

LANG=zh_CN.UTF-8
LC_CTYPE="zh_CN .UTF-8"
LC_NUMERIC="zh_ CN.UTF-8"
LC_TIME="zh_CN. UTF-8"
LC_COLLATE="zh_ CN.UTF-8"
LC_MONETARY="zh _CN.UTF-8"
LC_MESSAGES="zh _CN.UTF-8"
LC_PAPER="zh_CN .UTF-8"
LC_NAME="zh_CN. UTF-8"
LC_ADDRESS="zh_ CN.UTF-8"
LC_TELEPHONE="z h_CN.UTF-8"
LC_MEASUREMENT= "zh_CN.UTF-8"
LC_IDENTIFICATI ON="zh_CN.UTF-8"
LC_ALL=
Sep 13 '08
10 8212
On 916, 7ʱ06, rich...@cogsci. ed.ac.uk (Richard Tobin) wrote:
In article <baafde85-9eaf-4cd0-a62c-20744abd5...@v1 6g2000prc.googl egroups..com>,

how to write the string to the file using UTD-16 encoding? I also want
read this string from saved file.
You may be able to control this by setting the locale appropriately.

i run this code in windows. the oov.txt is an unicode in UTD-16
encoding file.
in linux, how to setting the locale appropriately. can you tell me how
to do? or
how can i get the information about this?
Sep 16 '08 #11

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

Similar topics

13
4593
by: Peter Maas | last post by:
Recently I replaced Win2k with Linux on my desktop computer. Using mostly multi-platform software I thought this would be easy. It was not as easy as expected getting wxPython to work. There seemed to be no SuSE RPM so I installed from source. Here are my steps (gtk 2.4 was already installed): - Built wxWidgets (.configure --enable-unicode) - Built wxPython (python setup.py install) error: "you should use wx-config program for...
12
8237
by: Mike Dee | last post by:
A very very basic UTF-8 question that's driving me nuts: If I have this in the beginning of my Python script in Linux: #!/usr/bin/env python # -*- coding: UTF-8 -*- should I - or should I not - be able to use non-ASCII characters in strings and in Tk GUI button labels and GUI window titles and in raw_input data without Python returning wrong case in manipulated
7
5114
by: Me | last post by:
I am trying to compile some code Ive gotten from another and I know I need a 16 bit unicode string, for he passes the pointer to functions that take a (uint16 *), however there are initializations that look like this. typedef unsigned short int ucs2_char; .... ....
2
9820
by: hezhenjie | last post by:
Hi, all: I just need to parse a unicode file, and assume to get data one line by one line. I use _wfopen(), fgetws(), wcslen(), wcsstr(), making it work normally on Windows platform. However, when migrate it to Linux platform, issue occurs. Linux only has fopen() function, and fgetws() could not correctly get lines, in fact, it gets nothing.
7
4207
by: Robert | last post by:
Hello, I'm using Pythonwin and py2.3 (py2.4). I did not come clear with this: I want to use win32-fuctions like win32ui.MessageBox, listctrl.InsertItem ..... to get unicode strings on the screen - best results according to the platform/language settings (mainly XP Home, W2K, ...). Also unicode strings should be displayed as nice as possible at the console with normal print-s to stdout (on varying platforms, different
5
11734
by: Josh | last post by:
Can anyone tell me how do we use Unicode characters in C++ ????
9
1957
by: Gerry | last post by:
I'm using pyExcelerator and xlrd to read and write data from and to two spreadsheets. I created the "read" spreadsheet by importing a text file - and I had no unicode aspirations. When I read a cell, it appears to be unicode u'Q1", say. I can try cleaning it, like this:
1
5879
by: erikcw | last post by:
Hi, I'm trying to insert some data from an XML file into MySQL. However, while importing one of the files, I got this error: Traceback (most recent call last): File "wa.py", line 304, in ? main() File "wa.py", line 257, in main curHandler.walkData()
1
3043
by: noopurtiwari | last post by:
Hi All, I am porting a windows c++ code on to linux platform.The problen is, it uses functions like _tfopen and _taccess which are wndows specific function for providing unicode support. i was interested in knowing : 1. how to enable unicode on linux. 2. Are there any equivalent functions for _tfopen _taccess() in linux that would enable unicode support. (After some investigation about fopen() i found that it might support unicode on...
1
5787
by: anonymous | last post by:
1 Objective to write little programs to help me learn German. See code after numbered comments. //Thanks in advance for any direction or suggestions. tk 2 Want keyboard answer input, for example: answer_str = raw_input(' Enter answer ') Herr
0
9671
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10846
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. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10551
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 captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10595
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 most users, this new feature is actually very convenient. If you want to control the update process,...
0
10254
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 choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
6979
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 into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5650
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 the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5828
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
3
3116
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 effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.