Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 118889
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T03:33:58+00:00 2026-05-11T03:33:58+00:00

I am interested in writing utf-8 encoded strings to a file. I did this

  • 0

I am interested in writing utf-8 encoded strings to a file.

I did this with low level functions open() and write(). In the first place I set the locale to a utf-8 aware character set with setlocale('LC_ALL', 'de_DE.utf8'). But the resulting file does not contain utf-8 characters, only iso8859 encoded umlauts. What am I doing wrong?

Addendum: I don’t know if my strings are really utf-8 encoded in the first place. I just keep them in the source file in this form: char *msg = 'Rote Grütze';

See screenshot for content of the textfile: alt text http://img19.imageshack.us/img19/9791/picture1jh9.png

  • 1 1 Answer
  • 1 View
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. 2026-05-11T03:33:58+00:00Added an answer on May 11, 2026 at 3:33 am

    Changing the locale won’t change the actual data written to the file using write(). You have to actually produce UTF-8 characters to write them to a file. For that purpose you can use libraries as ICU.

    Edit after your edit of the question: UTF-8 characters are only different from ISO-8859 in the ‘special’ symbols (ümlauts, áccénts, etc.). So, for all the text that doesn’t have any of this symbols, both are equivalent. However, if you include in your program strings with those symbols, you have to make sure your text editor treats the data as UTF-8. Sometimes you just have to tell it to.

    To sum up, the text you produce will be in UTF-8 if the strings within the source code are in UTF-8.

    Another edit: Just to be sure, you can convert your source code to UTF-8 using iconv:

    iconv -f latin1 -t utf8 file.c 

    This will convert all your latin-1 strings to utf8, and when you print them they will be definitely in UTF-8. If iconv encounters a strange character, or you see the output strings with strange characters, then your strings were in UTF-8 already.

    Regards,

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am interested in writing static code analyzer for vb.net to see if it
I'm interested in writing software that depends on being able to identify that there
I am interested in writing separate program modules that run as independent threads that
I'm interested in writing some basic computerized object recognition application, so I figure I
I am interested in writing a simplistic navigation application as a pet project. After
When writing a custom string class that stores UTF-8 internally (to save memory) rather
I am interested in writing an annotation processor for the maven-processor-plugin. I am relatively
I'm interested in writing a parsing engine such as the ones in Inform, which
I'm writing a GUI for an application using Swing, and in the interests of
There's a lot of interest these days in Erlang as a language for writing

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.