How do I reset EOF (ctrl-Z) after it has been typed on the keyboard and used.

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Charles Pique
    New Member
    • Sep 2010
    • 2

    #1

    How do I reset EOF (ctrl-Z) after it has been typed on the keyboard and used.

    I used ctrl-z to signal the sw to go and it reports faithfully (using cin.eof) that EOF has changed from 0 to 1. Now I want to reset EOF to 0 so I can use it again.
    I thought of rewind but this is not file work.
  • weaknessforcats
    Recognized Expert Expert
    • Mar 2007
    • 9214

    #2
    I don't think you can reset EOF. What it means is "end of all input" so I don't think you can change your mind and say "Hold it! There's more input".

    I suggest using a test other than EOF. Like maybe parsing the the input until the user enters "Done". Noe you can ask for more input and search for "Done" again.

    Comment

    • Charles Pique
      New Member
      • Sep 2010
      • 2

      #3
      In the beginner's program that I had, enter followed ctrl-z.
      Other beginner's programs used enter to signal that input was complete and they would go process. Then another line could be typed with enter and it would be processed in turn. That was a different command.
      I am reading Deitel chapter 21 about commands like cin.get and cin.eof. The EOF is reset if the program is ended and restarted (all this in the old Turbo C version 3 on a 486). It does not appear that their demonstration program for cin.eof is very useful for keyboard input.
      In any case the only specific task that I have to do is learn C.
      I am very concerned about I/O because I want to write code one day to control and monitor peripherals and that has usually been tricky.
      I try to find a way to undo anything that changes the machine state. That way I have complete control

      Comment

      • weaknessforcats
        Recognized Expert Expert
        • Mar 2007
        • 9214

        #4
        The EOF indeed is ctrl+z. However, you need to press enter to get the ctrl+z into the stdin stream.

        The ctrl+z signals the end of all input.

        With a real user, you can't control what is entered. All you can do is provide instructions that if the user enters certain data that your program will do certain things. Should the user fail to follow your insturctions and your program croaks, then what more is to be said?

        So the Deitel example is probablty OK as long as ctrl+z is used as directed.

        Comment

        Working...