Click here to Skip to main content
15,885,435 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
hi in the following code:
FILE *fp=fopen("f5.txt", "wt");
LPCWSTR uctext=L"سلام";
int stat=fputws(uctext,fp);
fclose(fp);

i get an empty file with stat=-1. why?! i expect fputws convert the unicode text which is in arabic language to multibyte string and write it to file.
any idea?
thx
Posted
Comments
André Kraak 14-Jan-14 12:20pm    
As stated in the fputws[^] documentation check the errno[^] to see what went wrong.
CPallini 14-Jan-14 13:36pm    
Your code looks correct. Don't know if it is a fputws bug. You may try a workaround.
Richard is correct, see his answer.

1 solution

I tested your code and received the error EILSEQ (42), which indicates that a character was found in the string that cannot be converted.

[edit]
Feedback from OP suggests that the WideCharToMultiByte function has been used to resolve the problem.
[/edit]
 
Share this answer
 
v2
Comments
CPallini 14-Jan-14 13:53pm    
My 5.
Richard MacCutchan 14-Jan-14 14:00pm    
Thanks, it took some finding.
ilostmyid2 15-Jan-14 1:25am    
thanx to both. yes, i checked errno and found the same value. but it's weird. what's in the string which cannot be converted? we know that all unicode characters have equivalents in multibyte sequence form. i changed it to a simpler unicode string, a single arabic letter seen (U+0633). i also thought the editor may not correctly provide the string. so i used "\x633" instead of entering the letter directly into the string. but the result was the same.
what's wrong?!
Richard MacCutchan 15-Jan-14 3:53am    
I am not certain of the answer but I think it has something to do with locale. Check the documentation at http://msdn.microsoft.com/en-us/library/5d7tc9zw.aspx, especially the remarks about using the _wcstombs_l function.
ilostmyid2 15-Jan-14 5:06am    
i added the following line:
_locale_t l = _get_current_locale();
i see that l.locinfo.lc_codepage is zero while the system locate is set to 1256. maybe visual studio (2010) doesn't know and may not adapt itself to system locale? wCodePage in l.locinfo.lc_id is also 0!

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

  Print Answers RSS
Top Experts
Last 24hrsThis month


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