Click here to Skip to main content
15,885,278 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
Hi,
I want to CREATE an INI file with UTF-8 encoding and read/write data from/to it using VC++(VC++6) on MS visual studio 6.Somebody please suggest how this can be done.Code will be more helpful.
Please note that this is in visual studio 6 (lot of help is already available with VS2003,VS2005 which is not serving the purpose).

please help me.

Thanks in Advance.
Posted
Updated 19-Jun-11 19:39pm
v2
Comments
Sergey Alexandrovich Kryukov 20-Jun-11 1:54am    
The code is more or less trivial but writing it would take time. How can you hope someone will do this work for you? Maybe you will find such code in Internet, but why not just writing such parser? Make the same interface as regular INI. Ask a question if you face a problem.
--SA
Sandeep Mewara 20-Jun-11 2:01am    
You want to, but did you try? If you try then you will be able to be more specific and helps more.
chandanadhikari 23-Jun-11 0:24am    
thanks for the comments guys :)

If we save our file in UTF-8 than we must add 3 BOM char first and than write data that we want to save in file.

For Example:
char strUTF8[] = { unsigned char(0xEF), unsigned char(0xBB), unsigned char(0xBF),'\0' };
CStdioFile m_OutPutFile;
m_OutPutFile.Open(strOPfileName,CFile::modeCreate|CFile::modeWrite|CFile::typeBinary);
m_OutPutFile.Write(strUTF8,strlen(strUTF8)*sizeof(char));
m_OutPutFile.Close();
 
Share this answer
 
Comments
chandanadhikari 20-Jun-11 2:39am    
Thanks for the reponse.
chandanadhikari 20-Jun-11 2:45am    
actually i want to skip the manually saving step.The file has to be created with utf-8 and then data written to it only once.
ShilpiP 20-Jun-11 2:52am    
Manually saving steps ??? If you want to create your file with UTF-8 than you must add these BOM character at the start of file else file is not saved in UTF-8 format.
chandanadhikari 20-Jun-11 3:37am    
thanks for the information :)i was totally neglecting this part.
chandanadhikari 27-Jun-11 7:44am    
Hi SP 24 !!! thanks for your help.Just wanted to know one more thing--i got the required .ini file using your info and used all wide character functions (fwprintf()wfopen()etc.etc.)in the code.Now the problem is that in the .ini file i am getting a space after every character--for eg."configuration" is shown as "c o n f i g u r a t i o n " when the file is opened in textpad .This is unwanted I mean this extra spacing should not be there.Please tell if there is solution to this problem.
thanks in advance :).
Are you sure you really need INI? It would take good amount of your working time with very limited results. However, see my comment to the question above.

I would suggest you use XML instead. Parser is readily available, and UTF-8 is standard-de-facto, many other charsets are supported, expressive ability is virtually unlimited.

—SA
 
Share this answer
 
Comments
chandanadhikari 20-Jun-11 2:51am    
Thanks for the response. Your suggestions are welcome but i need a .ini file only . please tell if i code using all the wide character functions (_fgetchar(),_fputwchar(),_wfopen()etc,etc.) do the trick for me as i am taking this approach.
Sergey Alexandrovich Kryukov 22-Jun-11 17:14pm    
The solution is pretty straightforward, you need to use UNICODE precompiler definition and use wide versions of all string processing, read all strings and classify them into section recognized by section format [%s], section_name.
--SA
chandanadhikari 22-Jun-11 23:31pm    
Thanks a lot for your response :).I have already implemented these things and they are serving the purpose pretty well.Can you please be more clear by what you mean by " classify them into section ... " .
Sergey Alexandrovich Kryukov 23-Jun-11 0:34am    
Oh, I simply mean the format is:
[Some_section name]
param1 = value
pa3 = value
[Some other section name]
par4 = value

param1 and pa3 are classifies into one section, par4 into another one...
I hope you have done that.

Ideally it could be associative array (a dictionary or hash table indexed with the structure {section_name, key_name} and values should be values. Also can be classified into type of values, with validation.

Not so interesting... I don't really understand why keeping such archaic feature...
--SA
chandanadhikari 23-Jun-11 4:58am    
OH!! i have already done that .anyways thanks for the help pal :)!!

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900