By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
424,962 Members | 1,776 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,962 IT Pros & Developers. It's quick & easy.

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

P: 2
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.
Sep 4 '10 #1
Share this Question
Share on Google+
3 Replies


weaknessforcats
Expert Mod 5K+
P: 9,197
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.
Sep 4 '10 #2

P: 2
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
Sep 5 '10 #3

weaknessforcats
Expert Mod 5K+
P: 9,197
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.
Sep 5 '10 #4

Post your reply

Sign in to post your reply or Sign up for a free account.