Value of EOF

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

    #1

    Value of EOF

    Alright, this is puzzling me. Here's what it says:

    Exercise 1-7. Write a program to print the value of EOF.

    Which is from the book "The C Programming Language". How would I go
    about writing that program, I honestly don't understand what it means,
    please help. Thanks.

  • Jason

    #2
    Re: Value of EOF


    Matt wrote:[color=blue]
    > Alright, this is puzzling me. Here's what it says:
    >
    > Exercise 1-7. Write a program to print the value of EOF.
    >
    > Which is from the book "The C Programming Language". How would I go
    > about writing that program, I honestly don't understand what it[/color]
    means,[color=blue]
    > please help. Thanks.[/color]

    EOF is simply an integer.

    Comment

    • Matt

      #3
      Re: Value of EOF

      0 or 1? If so, I just don't get how to do that...would it be like
      this?:

      #include <stdio.h>

      main()
      {
      int val1, val2;

      val1 = 1;
      val2 = 0;

      printf("EOF is equal to either: %d %d\n", val2, val1);
      }

      ? I'm not sure...

      Comment

      • Randy Howard

        #4
        Re: Value of EOF

        In article <1113953243.428 014.217450@f14g 2000cwb.googleg roups.com>,
        noXealia@gmail. com says...[color=blue]
        > 0 or 1? If so, I just don't get how to do that...would it be like
        > this?:
        >
        > #include <stdio.h>
        >
        > main()
        > {
        > int val1, val2;
        >
        > val1 = 1;
        > val2 = 0;
        >
        > printf("EOF is equal to either: %d %d\n", val2, val1);
        > }
        >
        > ? I'm not sure...[/color]

        You've got to be kidding. Please say you're joking.

        --
        Randy Howard (2reply remove FOOBAR)
        "Making it hard to do stupid things often makes it hard
        to do smart ones too." -- Andrew Koenig

        Comment

        • Martin Ambuhl

          #5
          Re: Value of EOF

          Matt wrote:[color=blue]
          > 0 or 1?[/color]

          No, EOF must be some negative integer. Neither 0 nor 1 qualifies.
          [color=blue]
          > If so, I just don't get how to do that...would it be like
          > this?:
          >
          > #include <stdio.h>
          > main()
          > {
          > int val1, val2;
          > val1 = 1;
          > val2 = 0;
          > printf("EOF is equal to either: %d %d\n", val2, val1);
          > }[/color]

          Not even close. This really isn't so hard:

          #include <stdio.h>

          int main(void)
          {
          printf("EOF == %d\n", EOF);
          return 0;
          }

          [(implementation-specific) output]
          EOF == -1

          Comment

          • Jason

            #6
            Re: Value of EOF


            Matt wrote:[color=blue]
            > 0 or 1?[/color]

            Neither. EOF is an integer value that is guaranteed to NOT be a valid
            char value. On my system it shows as -1, but it could easily be
            anything else on your system.
            [color=blue]
            >
            > #include <stdio.h>
            >
            > main()
            > {
            > int val1, val2;
            >
            > val1 = 1;
            > val2 = 0;
            >
            > printf("EOF is equal to either: %d %d\n", val2, val1);
            > }
            >
            > ? I'm not sure...[/color]

            How about printf("EOF=%d\ n",EOF) ?

            Comment

            • Jason

              #7
              Re: Value of EOF


              Randy Howard wrote:[color=blue]
              > You've got to be kidding. Please say you're joking.[/color]

              Be kind now. We were all in that some boat before.

              Comment

              • Keith Thompson

                #8
                Re: Value of EOF

                "Matt" <noXealia@gmail .com> writes:[color=blue]
                > 0 or 1? If so, I just don't get how to do that...would it be like
                > this?:[/color]

                Since you snipped the context, it's hard to tell what your "0 or 1?"
                refers to. Since I just read the parent article, I happen to know
                that Jason wrote "EOF is simply an integer." is the parent article.
                And the answer to your question is no; EOF does not have the value 0
                or 1. (Why would you assume that it does?)

                If you want to post a followup via groups.google.c om, don't use
                the broken "Reply" link at the bottom of the article. Click on
                "show options" at the top of the article, then click on the
                "Reply" at the bottom of the article headers.

                Hint: EOF is a macro defined in <stdio.h>. Your program (not quoted
                here) does not refer to EOF, so it can't print its value.

                --
                Keith Thompson (The_Other_Keit h) kst-u@mib.org <http://www.ghoti.net/~kst>
                San Diego Supercomputer Center <*> <http://users.sdsc.edu/~kst>
                We must do something. This is something. Therefore, we must do this.

                Comment

                • Matt

                  #9
                  Re: Value of EOF

                  I'm sorry for being stupid, but I just didn't understand the question
                  in the book. Now I do, thanks for helping Jason and Martin Ambuhl

                  Comment

                  • Jason

                    #10
                    Re: Value of EOF


                    Matt wrote:[color=blue]
                    > I'm sorry for being stupid, but I just didn't understand the question
                    > in the book. Now I do, thanks for helping Jason and Martin Ambuhl[/color]

                    It's only stupid if you know it's wrong and do it anyway. Having said
                    that...

                    General Netiquette FAQ:


                    Comp.lang.C FAQ:


                    -Jason

                    Comment

                    • Randy Howard

                      #11
                      Re: Value of EOF

                      In article <1113954479.458 240.132580@o13g 2000cwo.googleg roups.com>,
                      marlaque@hotmai l.com says...[color=blue]
                      >
                      > Randy Howard wrote:[color=green]
                      > > You've got to be kidding. Please say you're joking.[/color]
                      >
                      > Be kind now. We were all in that some boat before.[/color]

                      If you say so. In what schools do they teach that the set of
                      integers consists of the numbers 0 and 1 only? I want to be
                      sure not to send my children to one of them.



                      Comment

                      • Matt

                        #12
                        Re: Value of EOF

                        I never said those were the only integers I know. Shall I write them
                        all out for you?

                        1,2,3,4,5,6,7,8 ,9,10,11,12,13, 14,15,16,17,18, 19,20,21,22,23, 24,25,26,27,28, 29,30,31,32,etC .
                        I just didn't understand the question.

                        Comment

                        • Keith Thompson

                          #13
                          Re: Value of EOF

                          "Matt" <noXealia@gmail .com> writes:[color=blue]
                          > I never said those were the only integers I know. Shall I write them
                          > all out for you?
                          >
                          > 1,2,3,4,5,6,7,8 ,9,10,11,12,13, 14,15,16,17,18, 19,20,21,22,23, 24,25,26,27,28, 29,30,31,32,etC .
                          > I just didn't understand the question.[/color]

                          Several articles upthread, Jason wrote:

                          ] EOF is simply an integer.

                          Your response was:

                          ] 0 or 1? If so, I just don't get how to do that...would it be like
                          ] this?:
                          ]
                          ] #include <stdio.h>
                          ]
                          ] main()
                          ] {
                          ] int val1, val2;
                          ]
                          ] val1 = 1;
                          ] val2 = 0;
                          ]
                          ] printf("EOF is equal to either: %d %d\n", val2, val1);
                          ] }
                          ]
                          ] ? I'm not sure...

                          I'm sure you understand that 0 and 1 aren't the only integers, but
                          what you wrote *seemed* to imply exactly that.

                          I'm not trying to give you a hard time, just explaining why some of us
                          reacted the way we did. (I still don't understand where your "0 or 1?"
                          comment came from, but that's not important; if you've got a good
                          handle on it now, I suggest we just drop it and move on.)

                          --
                          Keith Thompson (The_Other_Keit h) kst-u@mib.org <http://www.ghoti.net/~kst>
                          San Diego Supercomputer Center <*> <http://users.sdsc.edu/~kst>
                          We must do something. This is something. Therefore, we must do this.

                          Comment

                          • Lawrence Kirby

                            #14
                            Re: Value of EOF

                            On Tue, 19 Apr 2005 16:46:12 -0700, Jason wrote:
                            [color=blue]
                            >
                            > Matt wrote:[color=green]
                            >> 0 or 1?[/color]
                            >
                            > Neither. EOF is an integer value that is guaranteed to NOT be a valid
                            > char value.[/color]

                            No, EOF is commonly defined as -1 on implementations where char is signed
                            i.e. can represent the value -1. EOF is required to be a negative value
                            which means that it can't be a valid *unsigned char* value. That's
                            relevant because functions like getchar() return a character represented
                            as an unsigned char value converted to int, so when such functions return
                            EOF it is a distinct value from any valid character (except in a certain
                            theoretical situation which isn't usually worth worrying about).
                            [color=blue]
                            > On my system it shows as -1, but it could easily be
                            > anything else on your system.[/color]

                            As long as it is a negative int value.

                            Lawrence

                            Comment

                            • Chris Croughton

                              #15
                              Re: Value of EOF

                              On Wed, 20 Apr 2005 13:29:21 +0100, Lawrence Kirby
                              <lknews@netacti ve.co.uk> wrote:
                              [color=blue]
                              > On Tue, 19 Apr 2005 16:46:12 -0700, Jason wrote:
                              >[color=green]
                              >> Matt wrote:[color=darkred]
                              >>> 0 or 1?[/color]
                              >>
                              >> Neither. EOF is an integer value that is guaranteed to NOT be a valid
                              >> char value.[/color]
                              >
                              > No, EOF is commonly defined as -1 on implementations where char is signed
                              > i.e. can represent the value -1. EOF is required to be a negative value
                              > which means that it can't be a valid *unsigned char* value. That's
                              > relevant because functions like getchar() return a character represented
                              > as an unsigned char value converted to int, so when such functions return
                              > EOF it is a distinct value from any valid character (except in a certain
                              > theoretical situation which isn't usually worth worrying about).[/color]

                              You're referring to sizeof int == 1 or some other case?

                              Is there any chance of dropping the "plain char may be signed" from the
                              spec. totally? Since it may be signed or unsigned no conforming code
                              can depend on it being signed, and everywhere I've seen signed char is
                              more of a problem (indeed, I don't think I've ever seen it required).

                              Chris C

                              Comment

                              Working...