fopen and encoding of "*filename" argument.

This is a discussion on fopen and encoding of "*filename" argument. within the C Programming forums, part of the General Programming Boards category; Hi, I have a c program which opens a file and copies bytes in this file to another. This can ...

  1. #1
    Registered User
    Join Date
    Jul 2005
    Posts
    8

    fopen and encoding of "*filename" argument.

    Hi,

    I have a c program which opens a file and copies bytes in this file to another. This can be run in many locales. It uses fopen() to open the file. The first argument to fopen() is const char* which is name/path of the file to open. What should be the encoding of this argument? Should it be in the encoding of the locale?

    Thanks,
    Vivek.

  2. #2
    Registered User
    Join Date
    Aug 2005
    Posts
    1,267
    I would think the filename would be encoded in whatever language is set up on the computer, or however the user wants to see the filenames on the disk in WindowsExplorer, which may or may not be in the same language. So I don't see how you need to worry about encoding at all -- C standards specify char*, so the characters of whatever language is used must fit in an unsigned char (not wchar_t).

  3. #3
    Registered User
    Join Date
    Jul 2005
    Posts
    8
    I have the filename in UTF8 encoding. Hence I need to convert it to the encoding which fopen() understands for the first argument, i.e. const char*. If I convert it to locale encoding lets say Japanese, then the bytes in the filename argument will be different than that if I convert it to some other locale encoding e.g. French.

    Please note that my concern is NOT about the stream/data in the file. I am talking about just first argument of fopen()

    Thanks,
    Vivek.

  4. #4
    Just Lurking Dave_Sinkula's Avatar
    Join Date
    Oct 2002
    Posts
    5,006
    Is this in the ballpark of your question?
    7. It is easier to write an incorrect program than understand a correct one.
    40. There are two ways to write error-free programs; only the third one works.*

  5. #5
    Mad OnionKnight's Avatar
    Join Date
    Jan 2005
    Location
    Umeň, Sweden
    Posts
    555
    If you have file to test on why not test it?

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. fopen and wfopen
    By George2 in forum C Programming
    Replies: 2
    Last Post: 08-20-2007, 10:28 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21