LinuxQuestions.org
Support LQ: Use code LQ3 and save $3 on Domain Registration
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
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.

Notices

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

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


Hi

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. http://www.tony-franks.co.uk/UTF-8.htm

LANG and LC_CTYPE env variables for my terminal session are set as follows.
LANG=en_US.UTF-8 and LC_CTYPE=en_US.UTF-8

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.
#include<stdio.h>
#include<wchar.h>
#include<locale.h>

int main()
{
FILE *fp=NULL;
fp=fopen("myfile.txt","w+");
setlocale(LC_CTYPE,"en_US.UTF-8");
unsigned char x=179;
unsigned char y=146;
printf("%c %d \n", x,x);
printf("%c %d \n", y,y);
fputc(x,fp);
fputc(y,fp);
return 0;
}

Output:
$./a.out
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.

Thanks,
Sathya
 
  


Reply

Tags
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


All times are GMT -5. The time now is 09:16 AM.

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