Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

fputws(Buf,FileStream) doesn't work

Status
Not open for further replies.

TheMillionDollarMan

Programmer
Jun 10, 2002
132
US
Hi,

I am using this function to print some japanese chars to a text file. It doesn't work however.
I am using
Windows 2000
VC6.0

The problem is that in the watch window I see the contents of buf and it looks fine. However when I open the text file fputws has printed everything before the Japanese chars and nothing after it.

Any ideas?

Thanks

wchar_t * buf = WSZALLOC(count);
size_t j = 0;
for (size_t i = 0; i < count; i++)
if (s != ZERO_WIDTH_SPACE)
buf[j++] = s;

buf[j] = L'\0';
fputws (buf, f);
 
Have you checked the return value from fputws? i.e.

int result = fputws(buf,f);

result will be non-negative if successful. If there is an error, it returns WEOF.
 
Yes I did. result returns say 3 when there is a whole line that should be about 137 chars long. ie I should see 137 and not 3.

Hmm. The output is garbage. Indicating to me that it can't find the right font however when I use the
AfxMessageBox(mychararray);
the message comes up with perfect japanese.
instead of
wEgýVµPÿt^
6
from the file
 
Solution:

char *mbcs_buf = (char*)malloc(count*2);
wcstombs( mbcs_buf, buf, count*2 );
fputs (mbcs_buf, f);
free(mbcs_buf);

fputs() is suppoed to convert your wchar_t from Unicode to MBCS but it doesn't....

So we did it manually and then sent it to the
fouts() function.

Peace out.

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top