EOF problem

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

    EOF problem

    I'm doing a decryption prog which read a enc. file and decrypt it. However,
    some of the encrypted text is the same as EOF and thus i cant read the text
    that after it. What should i do?

    I tried the getline and read.. but still cant work.. can anyone help me?


  • osmium

    #2
    Re: EOF problem

    BH writes:
    [color=blue]
    > I'm doing a decryption prog which read a enc. file and decrypt it.[/color]
    However,[color=blue]
    > some of the encrypted text is the same as EOF and thus i cant read the[/color]
    text[color=blue]
    > that after it. What should i do?
    >
    > I tried the getline and read.. but still cant work.. can anyone help me?[/color]

    There is no EOF character. EOF is a *condition*, not a character, at least
    in the context of a C++ program. Rethink your problem. The typical modern
    computer has 256 character codes, none of which denote EOF.


    Comment

    • Arne Schmitz

      #3
      Re: EOF problem

      osmium schrieb:
      [color=blue]
      > There is no EOF character.  EOF is a condition, not a character, at least
      > in the context of a C++ program.  Rethink your problem.  The typical
      > modern computer has 256 character codes, none of which denote EOF.[/color]

      Well, if he uses a Windows compiler and opened the file in textmode (without
      "b"-flag) using fopen(3), then he will stumble over EOF characters as they
      existed in the legacy ASCII character set.

      Posix ignores the "b"-flag and treats text- and binary files the same.

      Cheers,

      Arne

      --
      [--- PGP key FD05BED7 --- http://www.root42.de/ ---]

      Comment

      • David Harmon

        #4
        Re: EOF problem

        On Sun, 18 Apr 2004 19:09:43 +0800 in comp.lang.c++, "BH" <bbg@cc.com>
        wrote,[color=blue]
        >I'm doing a decryption prog which read a enc. file and decrypt it. However,
        >some of the encrypted text is the same as EOF and thus i cant read the text
        >that after it. What should i do?
        >
        >I tried the getline and read.. but still cant work.. can anyone help me?[/color]

        You must open the file in binary mode using the ios::binary openflag
        value. See e.g.:


        Comment

        • Kevin Goodsell

          #5
          Re: EOF problem

          Arne Schmitz wrote:
          [color=blue]
          > osmium schrieb:
          >
          >[color=green]
          >>There is no EOF character. EOF is a condition, not a character, at least
          >>in the context of a C++ program. Rethink your problem. The typical
          >>modern computer has 256 character codes, none of which denote EOF.[/color]
          >
          >
          > Well, if he uses a Windows compiler and opened the file in textmode (without
          > "b"-flag) using fopen(3), then he will stumble over EOF characters as they
          > existed in the legacy ASCII character set.[/color]

          Maybe, but as the man said, (C++) EOF is a condition, not a character.
          You cannot find (C++) EOF unless you are and the actual end of the file.
          Finding ASCII EOF does not cause (C++) EOF. Well, it could, but that
          would be the implementation' s fault. Obviously if that's the case he
          would need to decide on a solution, such as 1) use binary mode, or 2)
          make your text files valid for the host system (remove EOF characters
          that don't actually indicate EOF).

          -Kevin
          --
          My email address is valid, but changes periodically.
          To contact me please use the address from a recent posting.

          Comment

          • David Harmon

            #6
            Re: EOF problem

            On Sun, 18 Apr 2004 19:02:07 GMT in comp.lang.c++, Kevin Goodsell
            <usenet2.spamfr ee.fusion@never box.com> wrote,[color=blue]
            >Finding ASCII EOF does not cause (C++) EOF. Well, it could, but that
            >would be the implementation' s fault.[/color]

            It is perfectly within the range of allowable behavior for text mode.
            And might even have a justifiable reason in some case(*).
            If you do not like it, use binary mode like you are supposed to.

            (*)The origin of this nonsense was an ancient filesystem that did not
            store the exact file size, so text files needed a internal mark at the
            end after the final character. This was not C++'s fault or even C's
            fault.

            Comment

            • Kevin Goodsell

              #7
              Re: EOF problem

              David Harmon wrote:
              [color=blue]
              > On Sun, 18 Apr 2004 19:02:07 GMT in comp.lang.c++, Kevin Goodsell
              > <usenet2.spamfr ee.fusion@never box.com> wrote,
              >[color=green]
              >>Finding ASCII EOF does not cause (C++) EOF. Well, it could, but that
              >>would be the implementation' s fault.[/color]
              >
              >
              > It is perfectly within the range of allowable behavior for text mode.[/color]

              Yes, I didn't mean that the implementation would be in error. Just that
              it would be a somewhat unusual implementation, or at least behaving in a
              rather unexpected (though not wrong) way.

              -Kevin
              --
              My email address is valid, but changes periodically.
              To contact me please use the address from a recent posting.

              Comment

              • David Harmon

                #8
                Re: EOF problem

                On Sun, 18 Apr 2004 22:30:07 GMT in comp.lang.c++, Kevin Goodsell
                <usenet2.spamfr ee.fusion@never box.com> wrote,[color=blue]
                >David Harmon wrote:[color=green]
                >> It is perfectly within the range of allowable behavior for text mode.[/color]
                >
                >Yes, I didn't mean that the implementation would be in error. Just that
                >it would be a somewhat unusual implementation, or at least behaving in a
                >rather unexpected (though not wrong) way.[/color]

                More prevalent than any of us might wish.

                Comment

                • Jack Klein

                  #9
                  Re: EOF problem

                  On Sun, 18 Apr 2004 14:44:32 +0200, Arne Schmitz
                  <arne.schmitz@m mweg.rwth-aachen.de> wrote in comp.lang.c++:
                  [color=blue]
                  > osmium schrieb:
                  >[color=green]
                  > > There is no EOF character.  EOF is a condition, not a character, at least
                  > > in the context of a C++ program.  Rethink your problem.  The typical
                  > > modern computer has 256 character codes, none of which denote EOF.[/color]
                  >
                  > Well, if he uses a Windows compiler and opened the file in textmode (without
                  > "b"-flag) using fopen(3)[/color]

                  [snip]

                  "fopen(3)" is, of course, a constraint violation in standard C++,
                  since the prototype for fopen() is:

                  FILE *fopen(const char *filename, const char *mode);

                  ===

                  Yes, I know what you mean by "fopen(3)", but it's a reference to a
                  system-specific utility for viewing "man pages", nothing to do with C
                  or C++ or the definition of the function. And it's likely to confuse
                  newbies, most particularly those working on a Windows platform.

                  --
                  Jack Klein
                  Home: http://JK-Technology.Com
                  FAQs for
                  comp.lang.c http://www.eskimo.com/~scs/C-faq/top.html
                  comp.lang.c++ http://www.parashift.com/c++-faq-lite/
                  alt.comp.lang.l earn.c-c++

                  Comment

                  Working...