0

I'm getting some problems in creating files with file names of special characters in Mac OS X using C++.

This is is my App Print :
File Name is received from another executable thru sockets. (Most annoying thing is i have not been able to print the file name at all in terminal. It just shows question marks only.But when i write the file name to another file's content, it shows the exact characters.)

My App Print :

######
File Name before decoding : /Users/zeus/workspace/Unicodes/files/%D4%D3%C2%F3_1.txt
File Name after decoding :  /Users/zeus/workspace/Unicodes/files/????_1.txt
File Opened and Written #####

After the app is done, when i check for the file it shows % chars in file name. How is that possible ..?

zneak
  • 134,922
  • 42
  • 253
  • 328
Zeus
  • 571
  • 1
  • 7
  • 23

1 Answers1

2

My guess is that you need to encode your string as valid UTF-8. 0xD4 is not a valid UTF-8 character. Rather, the correct UTF-8 encoding for Ô is 0xC3 0x94 (it takes two bytes). It's impossible to say for sure because without seeing actual code, but this is my hunch. A more solid answer will need actual code.

It looks like your URL is encoding escape characters using the Latin-1 (ISO/IEC 8859-1) character set. This question talks about how to convert from ISO 8859-1 to UTF-8. Wikipedia has a good article on how UTF-8 is encoded.

Community
  • 1
  • 1
Cornstalks
  • 37,137
  • 18
  • 79
  • 144
  • Yes, on Mac OS X ["All BSD system functions expect their string parameters to be in UTF-8 encoding and nothing else."](https://developer.apple.com/library/mac/#documentation/MacOSX/Conceptual/BPInternational/Articles/FileEncodings.html) – bames53 Jan 07 '13 at 17:42
  • How to encode file name as valid UTF-8 in C++ ..? Sorry, i know it's a silly question. But all day i have been tired of this issue, i can't think straight. Can you please point me in the right direction. – Zeus Jan 07 '13 at 18:08
  • @Zeus: I added some links for how to convert to UTF-8 from ISO 8859-1. If you're still lost, leave a comment and I'll add more. – Cornstalks Jan 07 '13 at 18:59