fwrite, fgets binary file readback problem

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • CBFalconer

    #16
    Re: fwrite, fgets binary file readback problem

    Richard Tobin wrote:
    CBFalconer <cbfalconer@mai neline.netwrote :
    >
    .... snip quotation without attribution ...
    >
    >On *ix, but not doze. Under *ix the files are identical, under
    >doze there are \r in the char sequence for text files, which will
    >be absorbed if followed by a \n. This doesn't happen for a binary
    >file. And there are many other file systems.
    >
    I don't see the relevance of your comment. On both Unix and
    Windows, there is no difference between getc(), fgets(), and
    fread() in respect of how they handle line ends. They all
    convert them in text mode (and the conversion is a no-op in Unix),
    and none of them convert them in binary mode.
    If the raw file contains a cr lf sequence reading that file as text
    under Windoze will return \n. Under Unix it will return \r\n. If
    the file is opened as a binary file, Unix is unchanged, but Windoze
    will return \r\n.

    --
    [mail]: Chuck F (cbfalconer at maineline dot net)
    [page]: <http://cbfalconer.home .att.net>
    Try the download section.


    ** Posted from http://www.teranews.com **

    Comment

    • Richard Tobin

      #17
      Re: fwrite, fgets binary file readback problem

      In article <4849CB26.8F44B F95@yahoo.com>,
      CBFalconer <cbfalconer@mai neline.netwrote :
      >If the raw file contains a cr lf sequence reading that file as text
      >under Windoze will return \n. Under Unix it will return \r\n. If
      >the file is opened as a binary file, Unix is unchanged, but Windoze
      >will return \r\n.
      Once again I cannot see the relevance of your comment. I was saying
      that there is no difference between getc(), fread(), and fgets(),
      and you keep pointing out the difference between Unix and Windows.

      -- Richard
      --
      In the selection of the two characters immediately succeeding the numeral 9,
      consideration shall be given to their replacement by the graphics 10 and 11 to
      facilitate the adoption of the code in the sterling monetary area. (X3.4-1963)

      Comment

      • CBFalconer

        #18
        Re: fwrite, fgets binary file readback problem

        Richard Tobin wrote:
        CBFalconer <cbfalconer@mai neline.netwrote :
        >
        >If the raw file contains a cr lf sequence reading that file as text
        >under Windoze will return \n. Under Unix it will return \r\n. If
        >the file is opened as a binary file, Unix is unchanged, but Windoze
        >will return \r\n.
        >
        Once again I cannot see the relevance of your comment. I was saying
        that there is no difference between getc(), fread(), and fgets(),
        and you keep pointing out the difference between Unix and Windows.
        If you are unable to see that receiving different results on
        different systems requires the programmer to make appropriate
        adjustments, I suspect you should not be programming.

        --
        [mail]: Chuck F (cbfalconer at maineline dot net)
        [page]: <http://cbfalconer.home .att.net>
        Try the download section.


        ** Posted from http://www.teranews.com **

        Comment

        • Antoninus Twink

          #19
          Re: fwrite, fgets binary file readback problem

          On 7 Jun 2008 at 13:59, CBFalconer wrote:
          Richard Tobin wrote:
          >Once again I cannot see the relevance of your comment.
          That's because his comment had no relevance. Maybe in the past CBF was a
          reasonable programmer (though it's difficult to imagine based on the
          code snippets he posts here), but today there's no doubt that senility
          has set in and he's no longer capable of intelligent discussion. As
          you're discovering, trying to point out his numerous mistakes is just a
          recipe for frustration...
          If you are unable to see that receiving different results on
          different systems requires the programmer to make appropriate
          adjustments, I suspect you should not be programming.
          ....and breathtakingly arrogant and misdirected insults.

          Comment

          • Richard Tobin

            #20
            Re: fwrite, fgets binary file readback problem

            In article <484A9458.4BCA9 BB0@yahoo.com>,
            CBFalconer <cbfalconer@mai neline.netwrote :
            >If you are unable to see that receiving different results on
            >different systems requires the programmer to make appropriate
            >adjustments, I suspect you should not be programming.
            I give up. Your inability to follow a conversation makes it pointless
            for others to talk to to you.

            -- Richard
            --
            In the selection of the two characters immediately succeeding the numeral 9,
            consideration shall be given to their replacement by the graphics 10 and 11 to
            facilitate the adoption of the code in the sterling monetary area. (X3.4-1963)

            Comment

            • Richard Heathfield

              #21
              Re: fwrite, fgets binary file readback problem

              CBFalconer said:
              Richard Tobin wrote:
              >CBFalconer <cbfalconer@mai neline.netwrote :
              >>
              >>If the raw file contains a cr lf sequence reading that file as text
              >>under Windoze will return \n. Under Unix it will return \r\n. If
              >>the file is opened as a binary file, Unix is unchanged, but Windoze
              >>will return \r\n.
              >>
              >Once again I cannot see the relevance of your comment. I was saying
              >that there is no difference between getc(), fread(), and fgets(),
              >and you keep pointing out the difference between Unix and Windows.
              >
              If you are unable to see that receiving different results on
              different systems requires the programmer to make appropriate
              adjustments, I suspect you should not be programming.
              Chuck, for the Nth time this week you're being an idiot. You have
              completely misunderstood this discussion, and you owe Richard Tobin an
              apology for attacking him instead of understanding him. Going by your
              current form, however, I do not expect you to understand this.

              --
              Richard Heathfield <http://www.cpax.org.uk >
              Email: -http://www. +rjh@
              Google users: <http://www.cpax.org.uk/prg/writings/googly.php>
              "Usenet is a strange place" - dmr 29 July 1999

              Comment

              • CBFalconer

                #22
                Re: fwrite, fgets binary file readback problem

                Richard Heathfield wrote:
                CBFalconer said:
                >Richard Tobin wrote:
                >>CBFalconer <cbfalconer@mai neline.netwrote :
                >>>
                >>>If the raw file contains a cr lf sequence reading that file as text
                >>>under Windoze will return \n. Under Unix it will return \r\n. If
                >>>the file is opened as a binary file, Unix is unchanged, but Windoze
                >>>will return \r\n.
                >>>
                >>Once again I cannot see the relevance of your comment. I was saying
                >>that there is no difference between getc(), fread(), and fgets(),
                >>and you keep pointing out the difference between Unix and Windows.
                >>
                >If you are unable to see that receiving different results on
                >different systems requires the programmer to make appropriate
                >adjustments, I suspect you should not be programming.
                >
                Chuck, for the Nth time this week you're being an idiot. You have
                completely misunderstood this discussion, and you owe Richard Tobin an
                apology for attacking him instead of understanding him. Going by your
                current form, however, I do not expect you to understand this.
                The following is a copy of my original answer which has caused all
                this. All I did was point out an alternative to using fgets to
                read a binary file, by using gerc.

                --------------- start of quotation -------------
                Peter Nilsson wrote:
                Ben Pfaff wrote:
                >Jeff <jeep@rahul.net writes:
                >>
                >>Im trying to figure out why I cant read back a binary file correctly.
                >>...
                >> if (fgets((char *)buf, count, fp) == NULL)
                >>
                >fgets is not appropriate for reading binary data.
                >
                To be more precise, it's not appropriate for reading binary data that
                contains zero bytes. Since it doesn't return a length of characters
                read, there is no way to distinguish between a read null byte and
                the null byte with which it terminates the buffer (unless it's the
                last character in the buffer.)
                >
                It will also stop reading if it encounteres a '\n', which is often
                desired with text streams, but not so much with binary streams.
                >
                The fact that fgets doesn't cope with null bytes in streams is often
                a good reason to ignore it for parsing text streams in programs
                that need an extra level of robustness.
                However there is no restriction against using getc (or fgetc),
                which will convert the '\n's from text files correctly, and pass
                all the zero bytes. This makes the code depend only on the actual
                file type. getc, if macro implemented, will be just as fast, and
                eliminates the need for a buffer array.
                ------------ end of quotation ------------

                This generated an attack on my answer by Mr Tobin, which I have
                answered several times.

                --
                [mail]: Chuck F (cbfalconer at maineline dot net)
                [page]: <http://cbfalconer.home .att.net>
                Try the download section.


                ** Posted from http://www.teranews.com **

                Comment

                • Richard Heathfield

                  #23
                  Re: fwrite, fgets binary file readback problem

                  CBFalconer said:
                  Richard Heathfield wrote:
                  >CBFalconer said:
                  >>Richard Tobin wrote:
                  >>>CBFalconer <cbfalconer@mai neline.netwrote :
                  >>>>
                  >>>>If the raw file contains a cr lf sequence reading that file as text
                  >>>>under Windoze will return \n. Under Unix it will return \r\n. If
                  >>>>the file is opened as a binary file, Unix is unchanged, but Windoze
                  >>>>will return \r\n.
                  >>>>
                  >>>Once again I cannot see the relevance of your comment. I was saying
                  >>>that there is no difference between getc(), fread(), and fgets(),
                  >>>and you keep pointing out the difference between Unix and Windows.
                  >>>
                  >>If you are unable to see that receiving different results on
                  >>different systems requires the programmer to make appropriate
                  >>adjustments , I suspect you should not be programming.
                  >>
                  >Chuck, for the Nth time this week you're being an idiot. You have
                  >completely misunderstood this discussion, and you owe Richard Tobin an
                  >apology for attacking him instead of understanding him. Going by your
                  >current form, however, I do not expect you to understand this.
                  >
                  The following is a copy of my original answer which has caused all
                  this. All I did was point out an alternative to using fgets to
                  read a binary file, by using gerc.
                  >
                  --------------- start of quotation -------------
                  <snip>
                  >
                  However there is no restriction against using getc (or fgetc),
                  which will convert the '\n's from text files correctly, and pass
                  all the zero bytes. This makes the code depend only on the actual
                  file type. getc, if macro implemented, will be just as fast, and
                  eliminates the need for a buffer array.
                  ------------ end of quotation ------------
                  >
                  This generated an attack on my answer by Mr Tobin, which I have
                  answered several times.
                  Well done; you have shown that you *can* find old articles if you try. Now
                  try reading them, and you'll find that Mr Tobin is making a point that
                  appears so far to have flown right over your head - it is nothing to do
                  with Windows or Unix; rather, it's about fread, *getc, and fgets. Here is
                  his original reply to the first sentence of your above quote:

                  --------------- start of quotation -------------
                  All the stdio functions will convert line ends in text mode, and not
                  in binary mode. There's no difference between getc(), fgets(), and
                  fread() in this respect.
                  ------------ end of quotation ------------ (Richard Tobin)

                  I don't see how you read that as an attack, but note that here he is
                  pointing out that line end conversion (whether or not it turns out to be a
                  nop) is dependent on *mode*, not on platform or stdlib-function-name. If,
                  as certainly seems to me to be the case, you have failed to grasp this
                  point before, please grasp it now.

                  --
                  Richard Heathfield <http://www.cpax.org.uk >
                  Email: -http://www. +rjh@
                  Google users: <http://www.cpax.org.uk/prg/writings/googly.php>
                  "Usenet is a strange place" - dmr 29 July 1999

                  Comment

                  • Richard Tobin

                    #24
                    Re: fwrite, fgets binary file readback problem

                    In article <484B18F7.D2A33 897@yahoo.com>,
                    CBFalconer <cbfalconer@mai neline.netwrote :
                    >However there is no restriction against using getc (or fgetc),
                    >which will convert the '\n's from text files correctly, and pass
                    >all the zero bytes. This makes the code depend only on the actual
                    >file type. getc, if macro implemented, will be just as fast, and
                    >eliminates the need for a buffer array.
                    >This generated an attack on my answer by Mr Tobin, which I have
                    >answered several times.
                    Your phrase "getc ... which will convert the \n's ... correctly" might
                    have been interpreted as meaning that there was something special
                    about getc(), in particular as compared with fread() which others had
                    mentioned. So I pointed out that there was no difference in how they
                    handled line ends.

                    I don't see how you can interpret that as an attack.

                    -- Richard
                    --
                    In the selection of the two characters immediately succeeding the numeral 9,
                    consideration shall be given to their replacement by the graphics 10 and 11 to
                    facilitate the adoption of the code in the sterling monetary area. (X3.4-1963)

                    Comment

                    • CBFalconer

                      #25
                      Re: fwrite, fgets binary file readback problem

                      Richard Tobin wrote:
                      >
                      .... snip ...
                      >
                      I don't see how you can interpret that as an attack.
                      I think we should all drop this matter in favour of not creating
                      wars from misunderstandin gs.

                      --
                      [mail]: Chuck F (cbfalconer at maineline dot net)
                      [page]: <http://cbfalconer.home .att.net>
                      Try the download section.

                      ** Posted from http://www.teranews.com **

                      Comment

                      • Richard Heathfield

                        #26
                        Re: fwrite, fgets binary file readback problem

                        CBFalconer said:
                        Richard Tobin wrote:
                        >>
                        ... snip ...
                        >>
                        >I don't see how you can interpret that as an attack.
                        >
                        I think we should all drop this matter in favour of not creating
                        wars from misunderstandin gs.
                        I think you owe Richard Tobin an apology for misunderstandin g not only his
                        argument but also his motive.

                        --
                        Richard Heathfield <http://www.cpax.org.uk >
                        Email: -http://www. +rjh@
                        Google users: <http://www.cpax.org.uk/prg/writings/googly.php>
                        "Usenet is a strange place" - dmr 29 July 1999

                        Comment

                        • Richard

                          #27
                          Re: fwrite, fgets binary file readback problem

                          Richard Heathfield <rjh@see.sig.in validwrites:
                          CBFalconer said:
                          >
                          >Richard Tobin wrote:
                          >>>
                          >... snip ...
                          >>>
                          >>I don't see how you can interpret that as an attack.
                          >>
                          >I think we should all drop this matter in favour of not creating
                          >wars from misunderstandin gs.
                          >
                          I think you owe Richard Tobin an apology for misunderstandin g not only his
                          argument but also his motive.
                          I think you spend too much time telling people who to and when to
                          apologise.

                          Comment

                          • Kenny McCormack

                            #28
                            Re: fwrite, fgets binary file readback problem

                            In article <g2iqdk$4em$1@r egistered.motza rella.org>,
                            Richard <rgrdev@gmail.c omwrote:
                            >Richard Heathfield <rjh@see.sig.in validwrites:
                            >
                            >CBFalconer said:
                            >>
                            >>Richard Tobin wrote:
                            >>>>
                            >>... snip ...
                            >>>>
                            >>>I don't see how you can interpret that as an attack.
                            >>>
                            >>I think we should all drop this matter in favour of not creating
                            >>wars from misunderstandin gs.
                            >>
                            >I think you owe Richard Tobin an apology for misunderstandin g not only his
                            >argument but also his motive.
                            >
                            >I think you spend too much time telling people who to and when to
                            >apologise.
                            >
                            I have always assumed that someone had setup a web site (something like
                            www.clc.org/apologies) to keep track of who owes who what, debts
                            outstanding, debts paid, interest owed, etc).

                            Was I wrong?

                            Comment

                            Working...