CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums
Results 1 to 2 of 2

Thread: A question regarding reading unicode

  1. #1
    Join Date
    Jul 2005

    A question regarding reading unicode

    Basically I am trying to read unicode from a text file and this text file is saved as ansi code. Here is the code,
      int main()
    	TCHAR line[256];
    	FILE* file = _tfopen(_T("C:\\Temp\\test.txt"), _T("r"));
    		return 1;
    	int len;
    	while(_fgetts(line, 256, file))
            return 0;
    If test.txt is something like the following,
    Then when I read first line, the string always looks like L't', L'e', L's', L't', L'1', L'', 0. There is always one more character L'' is attached. I don't know why? Is there anything I should consider when reading unicode from file. Besides, if I save test.txt as unicode and then I read test.txt same way, then I get a messy output. I couldn't figure out why? Thanks.

  2. #2
    Join Date
    Apr 2009

    Re: A question regarding reading unicode

    _fgetts(), as well as fgets(), include the newline character.

    This is why it is customary to trim the buffer, after it is read with _fgetts().

    For instance:
    line[_tcslen(line) - 1] = _T('\0');

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Windows Mobile Development Center

Click Here to Expand Forum to Full Width

On-Demand Webinars (sponsored)