How to input EOF?

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

    How to input EOF?

    I wrote a short c code as follow:

    #include <stdio.h>
    int main()
    {
    int c;
    while ((c = getchar()) != EOF)
    putchar(c);
    }

    It works,but I don't know how to input the EOF so that I can stop the
    program,hope you can help me,thanks.

  • Dean

    #2
    Re: How to input EOF?

    I have found how to input EOF in old post , thanks any way!

    Comment

    • Vallabha

      #3
      Re: How to input EOF?

      On Sep 29, 12:33 pm, Dean <dingjiu.e...@g mail.comwrote:
      I wrote a short c code as follow:
      >
      #include <stdio.h>
      int main()
      {
          int c;
          while ((c = getchar()) != EOF)
              putchar(c);
      >
      }
      >
      It works,but I don't know how to input the EOF so that I can stop the
      program,hope you can help me,thanks.
      Enter "^D" (Control-D).

      cheers
      -Vallabha
      ==============
      S7 Software solutions

      Comment

      • Lew Pitcher

        #4
        Re: How to input EOF?

        On September 29, 2008 08:41, in comp.lang.c, Vallabha
        (vsnadagouda@gm ail.com) wrote:
        On Sep 29, 12:33 pm, Dean <dingjiu.e...@g mail.comwrote:
        >I wrote a short c code as follow:
        >>
        >#include <stdio.h>
        >int main()
        >{
        >int c;
        >while ((c = getchar()) != EOF)
        >putchar(c);
        >>
        >}
        >>
        >It works,but I don't know how to input the EOF so that I can stop the
        >program,hope you can help me,thanks.
        >
        Enter "^D" (Control-D).
        Oh? Which OS, shell, and settings? If you say "Unix", then prepare to defend
        your statement (and read up on stty).

        For Microsoft Windows, the OP would have to enter ^Z on an empty line


        --
        Lew Pitcher

        Master Codewright & JOAT-in-training | Registered Linux User #112576
        http://pitcher.digitalfreehold.ca/ | GPG public key available by request
        ---------- Slackware - Because I know what I'm doing. ------


        Comment

        • CBFalconer

          #5
          Re: How to input EOF?

          Lew Pitcher wrote:
          Vallabha (vsnadagouda@gm ail.com) wrote:
          >Dean <dingjiu.e...@g mail.comwrote:
          >>
          >>I wrote a short c code as follow:
          >>>
          >>#include <stdio.h>
          >>int main() {
          >>int c;
          >>while ((c = getchar()) != EOF)
          >>putchar(c);
          >>}
          >>>
          >>It works,but I don't know how to input the EOF so that I can
          >>stop the program,hope you can help me,thanks.
          >>
          >Enter "^D" (Control-D).
          >
          Oh? Which OS, shell, and settings? If you say "Unix", then
          prepare to defend your statement (and read up on stty).
          >
          For Microsoft Windows, the OP would have to enter ^Z on an empty
          line
          As a curiosity, note that entering (without the quotes):

          "aBS^Z"

          where BS is the backspace, and ^Z is Control-Z, is an EOF on
          Winders or MsDOS. Replace the BS with something else and it isn't.

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

          Comment

          • Richard Tobin

            #6
            Re: How to input EOF?

            In article <debd057c-60f1-4521-ac52-f34104330335@i2 4g2000prf.googl egroups.com>,
            Vallabha <vsnadagouda@gm ail.comwrote:
            >It works,but I don't know how to input the EOF so that I can stop the
            >program,hope you can help me,thanks.
            >Enter "^D" (Control-D).
            As other have pointed out, the exact character may vary - control-Z is
            also common.

            But a more important point is that you're not typing in an "EOF character"
            in the sense that C sees it. You're typing something that indicates the
            end of file, and it is quite unrelated to the EOF value returned by
            getc() etc. getc() returns EOF even at the end of a disk file, which
            on most modern operating systems doesn't have any kind of character
            representing it in the file: it's just what getc() returns when it
            gets to the end of the file.

            -- Richard
            --
            Please remember to mention me / in tapes you leave behind.

            Comment

            • Keith Thompson

              #7
              Re: How to input EOF?

              CBFalconer <cbfalconer@yah oo.comwrites:
              Lew Pitcher wrote:
              >Vallabha (vsnadagouda@gm ail.com) wrote:
              >>Dean <dingjiu.e...@g mail.comwrote:
              [...]
              >>>It works,but I don't know how to input the EOF so that I can
              >>>stop the program,hope you can help me,thanks.
              >>>
              >>Enter "^D" (Control-D).
              >>
              >Oh? Which OS, shell, and settings? If you say "Unix", then
              >prepare to defend your statement (and read up on stty).
              >>
              >For Microsoft Windows, the OP would have to enter ^Z on an empty
              >line
              >
              As a curiosity, note that entering (without the quotes):
              >
              "aBS^Z"
              >
              where BS is the backspace, and ^Z is Control-Z, is an EOF on
              Winders or MsDOS. Replace the BS with something else and it isn't.
              Of course. Typing backspace changes the formerly empty line into an
              empty line. The same thing happens on Unix-like systems (though the
              particular characters used can be reconfigured).

              The more general point is that the system can perform various
              operations on the input you type before presenting it to your program.
              (Some systems may let you reconfigure this behavior in various ways.)

              What the program sees isn't necessarily what was typed at the keyboard
              -- but that's not a problem as far as the standard is concerned,
              because it doesn't even mention keyboards.

              --
              Keith Thompson (The_Other_Keit h) kst-u@mib.org <http://www.ghoti.net/~kst>
              Nokia
              "We must do something. This is something. Therefore, we must do this."
              -- Antony Jay and Jonathan Lynn, "Yes Minister"

              Comment

              Working...