CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Page 1 of 2 12 LastLast
Results 1 to 15 of 17
  1. #1
    Join Date
    Oct 2001
    Location
    Texas, USA
    Posts
    339

    What is this file?

    I have a file that has a character then alternates with a null thru the entire file. When I open it in notepad i just see the characters next to each other no null or spaces. I see the nulls as squares in word if i open it that way. When i read the file i have to read it 1 byte at a time so that i can grab the character and skip the null, grap, skip and so on.

    So i have 2 questions:

    1. What kind of file is this and
    2. Is there a better and faster way to read this than 1 byte at a time.

    I am using CFile to read it right now.

    Any help would be very much appreciated.

    Thank you,

  2. #2
    Join Date
    Oct 2002
    Location
    Timisoara, Romania
    Posts
    14,360

    Re: What is this file?

    It is probably a binary file (as opposed to text files). Yes, you can read as many characters as you want at a time. Function Read() gets a pointer to a buffer and the size of the buffer. It can be any size you want.
    Marius Bancila
    Home Page
    My CodeGuru articles

    I do not offer technical support via PM or e-mail. Please use vbBulletin codes.

  3. #3
    Join Date
    Oct 2001
    Location
    Texas, USA
    Posts
    339

    Re: What is this file?

    when i do this:

    CFile myfile;

    myfile.open("C:\file.txt");

    myfile.Read (pbuf,100);

    It still gets the NULLs too and really messes me up when i try to move it to a CString. So what is the best way to read this? I need to remove the NULLs before i put the info into a DB.

    Thanks,
    Last edited by strych9; August 12th, 2009 at 01:31 PM.

  4. #4
    Join Date
    Jun 2005
    Posts
    315

    Re: What is this file?

    Possibly a unicode representation?

  5. #5
    Join Date
    Apr 2007
    Posts
    162

    Re: What is this file?

    Try using CStdioFile::ReadString

  6. #6
    Lindley is offline Elite Member Power Poster
    Join Date
    Oct 2007
    Location
    Seattle, WA
    Posts
    10,895

    Re: What is this file?

    It's probably a UTF-16 encoded file.

  7. #7
    Join Date
    Oct 2001
    Location
    Texas, USA
    Posts
    339

    Re: What is this file?

    can anyone give some code on how to read this?

    Thanks,

  8. #8
    Join Date
    Aug 2008
    Location
    Scotland
    Posts
    379

    Re: What is this file?

    Hi,

    You mention CString, so I guess you are using MFC.

    Compile your application as unicode and it should work fine, use CFile::Read to read it into the CString.

    Alan

  9. #9
    Join Date
    Oct 2001
    Location
    Texas, USA
    Posts
    339

    Re: What is this file?

    where is the setting to compile as unicode?

  10. #10
    Join Date
    Aug 2008
    Location
    Scotland
    Posts
    379

    Re: What is this file?

    Hi,
    Try this:
    http://www.mihai-nita.net/article.php?artID=20060723a

    or if that's not enough, this: :-)
    http://lmgtfy.com/?q=define+unicode+Visual+studio



    Best regards,
    Alan

  11. #11
    Join Date
    Oct 2001
    Location
    Texas, USA
    Posts
    339

    Re: What is this file?

    Thank you,
    Last edited by strych9; August 15th, 2009 at 12:52 PM.

  12. #12
    Join Date
    Oct 2001
    Location
    Texas, USA
    Posts
    339

    Re: What is this file?

    Well when i did that i got 51 errors on a program that was working? Any ideas?

  13. #13
    Join Date
    Mar 2006
    Posts
    63

    Re: What is this file?

    Can you post the file? Or where can I find it? Maybe once I can look at it I might be able to help.

  14. #14
    Join Date
    Apr 1999
    Posts
    27,449

    Re: What is this file?

    Quote Originally Posted by strych9 View Post
    I have a file that has a character then alternates with a null thru the entire file.
    This sounds like a Unicode version of a file that used to be in a single-byte character set,

    For example, a non-Unicode English text file that has been "Unicode-ized" will have the property you're describing.

    Regards,

    Paul McKenzie

  15. #15
    Join Date
    Oct 2001
    Location
    Texas, USA
    Posts
    339

    Re: What is this file?

    what is the best way to read it?

Page 1 of 2 12 LastLast

Posting Permissions

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





Click Here to Expand Forum to Full Width

Featured