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

Thread: Does random files are always in binary format and not in text format?

  1. #1

    Does random files are always in binary format and not in text format?

    Does random files are always in binary format and not in text format?

  2. #2
    Join Date
    Jan 2009
    Posts
    1,689

    Re: Does random files are always in binary format and not in text format?

    I'm sorry, I don't understand the question, in C and C++ you choose whether or not to write in binary or text.

  3. #3
    Join Date
    Jun 2010
    Location
    Germany
    Posts
    2,675

    Re: Does random files are always in binary format and not in text format?

    In theory, no. But because text-mode files usually have variable line lengths, there is no easy way to determine the position of any particular record in the file. It is possible to use padding to achieve a consistent record length to simplify random-access to records in a pure text file, but in fact I have never actually seen that being done in slightly more than three decades of programming and it would be pretty risky to manipulate files like this using an ordinary text editor. (Of course, binary files can contain fields consisting of readable text and that is not uncommon.)

    HTH
    Last edited by Eri523; December 10th, 2010 at 07:00 PM.
    I was thrown out of college for cheating on the metaphysics exam; I looked into the soul of the boy sitting next to me.

    This is a snakeskin jacket! And for me it's a symbol of my individuality, and my belief... in personal freedom.

  4. #4
    GCDEF is offline Elite Member Power Poster
    Join Date
    Nov 2003
    Location
    Florida
    Posts
    12,591

    Re: Does random files are always in binary format and not in text format?

    Quote Originally Posted by forumuser11@gmail.com View Post
    Does random files are always in binary format and not in text format?
    Wow.

  5. #5
    Join Date
    Feb 2002
    Posts
    4,640

    Re: Does random files are always in binary format and not in text format?

    Quote Originally Posted by Eri523 View Post
    In theory, no. But because text-mode files usually have variable line lengths, there is no easy way to determine the position of any particular record in the file. It is possible to use padding to achieve a consistent record length to simplify random-access to records in a pure text file, but in fact I have never actually seen that being done in slightly more than three decades of programming and it would be pretty risky to manipulate files like this using an ordinary text editor. (Of course, binary files can contain fields consisting of readable text and that is not uncommon.)

    HTH
    Well, technically, there's no difference between "text" and "binary" files. All files are binary. On windows platforms the difference come in, in the "layer" that reads and writes the data. That being, a carriage return/linefeed is read as a linefeed (or something to that effect). On *NIX boxes, "text" mode and "binary" mode mean exactly the same thing.

    Viggy

  6. #6
    Join Date
    Jan 2009
    Posts
    1,689

    Re: Does random files are always in binary format and not in text format?

    In C, all functions that deal with io default to using text. Haven't looked at the fstreams, but I would assume they do too.

    But like MrViggy said, they behave the same way on almost all computers.

  7. #7
    Join Date
    Oct 2006
    Location
    Sweden
    Posts
    3,654

    Re: Does random files are always in binary format and not in text format?

    In addition to what's already said, in text mode a Ctrl-Z marks the end of the file.
    Debugging is twice as hard as writing the code in the first place.
    Therefore, if you write the code as cleverly as possible, you are, by
    definition, not smart enough to debug it.
    - Brian W. Kernighan

    To enhance your chance's of getting an answer be sure to read
    http://www.codeguru.com/forum/announ...nouncementid=6
    and http://www.codeguru.com/forum/showthread.php?t=366302 before posting

    Refresh your memory on formatting tags here
    http://www.codeguru.com/forum/misc.php?do=bbcode

    Get your free MS compiler here
    https://visualstudio.microsoft.com/vs

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)