Click to See Complete Forum and Search --> : Reading The Unicode Format File


poojapatel
April 20th, 2005, 07:23 AM
Hi Friends

I had problem in reading a file which is in unicode format .
Even i am reading file using unicode commands it returns junk characters.

FILE *fPLog = fopen("D:\\Jitendra\\MSILog.txt","r");
WCHAR chBuffer[100] = L"";
if(fPLog)
{
while( !feof(fPLog) )
{ wscanf(fPLog,L"%hS",chBuffer);
wprintf(L"%hS\n",chBuffer);

}
fclose(fPLog);
}

i had written the above code and i get two junk characters and then all time i get the space in wprintf() function. plz help me to read the file it is very urgent.
if there is any ohter way then also you can suggest me, I am devloping in VC++ with console application.


Thanks in Advance.

With Regards
Jitendra Patel

hankdane
April 20th, 2005, 01:19 PM
The 'junk characters' is probably the Unicode signature. You can check this signature to get the format used in the file:

0xEE, 0xBB, 0xBF: UTF-8
0xFF, 0xFE: Unicode (UCS)
0xFE, 0xFF: Unicode, UCS, Big Endian

I don't know the answer to your other question. With Unicode files, I normally read it in binary mode, since some of the special bytes tend to trip up text-mode reading, especially every second 0-byte when you have English text in UCS format.