I am wondering if there is any way to detect the end of a user's input in a console app without having to use a sentinel character. Will someone please help me?
Printable View
I am wondering if there is any way to detect the end of a user's input in a console app without having to use a sentinel character. Will someone please help me?
Well in C, its
I imagine that the cin.getline() or whatever functions return some useful status to indicate end of file.Code:while ( fgets( buff, sizeof buff, stdin ) != NULL ) {
// do stuff
}
You normally signal EOF on stdin by typing either ctrl-z or ctrl-d (depending on your OS)
>I imagine that the cin.getline() or whatever functions return some useful status to indicate end of file.
Yep, istreams have an implicit conversion that allows simple status checking:
Code:while ( cin.getline ( buff, sizeof buff ) ) {
// Do stuff
}
Perhaps he wants to know if he read the whole line, inwhich case he needs to check to make sure the last character is '\n'. If you use a loop it will keep on begging for input until they give EOF (or an error occures) which is usually not what someone desires.
thanks a lot orbitz