Thread: Difference between reading a file in binary and ready only mode?

  1. #1
    Registered User
    Join Date
    Jul 2005
    Posts
    6

    Difference between reading a file in binary and ready only mode?

    I just wanted to know what the difference between opening a file as "r" and "rb" is? I thought C stored all values as the ASCII value? So doesn't this mean that is I opened a file in read only mode and displayed the hex value it would be the same as if I opened a file in binary mode?
    Any help would be appreciated
    Thanks in advance.

  2. #2
    Registered Luser cwr's Avatar
    Join Date
    Jul 2005
    Location
    Sydney, Australia
    Posts
    869
    I'm getting deja-vu here. This is pretty much the same question as this:

    http://cboard.cprogramming.com/showthread.php?t=69912

    The answers in that thread apply to reading as well as writing.

  3. #3
    Registered User
    Join Date
    Jul 2005
    Posts
    6
    Thanks for that reply cwr
    That is what I thought, so technically in unix there is no difference between text mode and binary mode? I mean no additions are made to the file like in the case of a windows machine it adds a carriage return before the new line.
    If that is right what happens to the '\r' if I were to create a file on a windows system and then open that file in linux in text mode or will I have to deal with the '\r' in my code?
    Thanks

  4. #4
    Registered User
    Join Date
    Sep 2004
    Location
    California
    Posts
    3,268
    so technically in unix there is no difference between text mode and binary mode?
    Correct

    If that is right what happens to the '\r' if I were to create a file on a windows system and then open that file in linux in text mode or will I have to deal with the '\r' in my code?
    Im pretty sure that in this case Linux would keep the \r, and you would have to deal with it in your code. That is why a lot of times when you save a file on windows, then open it up in vi on linux, you see an unknown character at the end of every line.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Searching Binary Files for a Pattern
    By CaptainMorgan in forum C Programming
    Replies: 16
    Last Post: 06-17-2007, 06:04 PM
  2. WAV file problems...
    By snerl in forum C Programming
    Replies: 4
    Last Post: 06-11-2003, 03:00 PM