Help answer threads with 0 replies.
Go Back > Forums > Non-*NIX Forums > Programming
User Name
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.


  Search this Thread
Old 05-06-2009, 09:18 AM   #1
Registered: Sep 2007
Posts: 33

Rep: Reputation: 15
Regarding Problem writing UTF8 characters to a file


My application running in Linux connects to informix database and fetches data from a TEXT column. The column content has some extended characters. For ex: XXXX and AAAA. The two characters and have value 179 and 146 which i found by printing in the code as well as from the website.
Please refer to the below line for the number and characters against them.

LANG and LC_CTYPE env variables for my terminal session are set as follows.

My issue is:
When i print 146 using %c , instead of getting the expected character i get only null character but character for 179 is printed properly and when i send both characters to file and do a cat of that file, the character for 179 is displayed properly. But when i do a vi of that file name, it is showing some junk.

Here is the program.

int main()
unsigned char x=179;
unsigned char y=146;
printf("%c %d \n", x,x);
printf("%c %d \n", y,y);
return 0;

179 ---> this is correct
146 ---> Unfortunately this is null character (not even a space)

$cat myfile.txt

Cat displays properly
But vi myfile.txt shows, ³<92>

Can you let me know what is the issue? why vi is not showing properly. I am not able migrate this data into a table in oracle also.
should i use iconv? If so how to use it.

when i say file myfile.txt
myfile.txt: Non-ISO extended-ASCII text, with no line terminators

Kindly help.



character, utf8

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
Problem with writing in a text file in C manolakis Programming 5 12-06-2006 10:18 PM
Problem writing file to iPod using gtkpod tdotman Linux - Software 12 01-23-2006 11:30 PM
Problem in C--double writing to file zaichik Programming 7 08-20-2005 04:38 PM
Problem printing a few characters in a PDF File provo1234 Linux - General 1 04-25-2005 08:08 AM
problem with writing into a file using socket(perl) akaash Programming 3 04-08-2004 06:06 AM > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 07:40 AM.

Main Menu
Write for LQ is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration