Hi
I found the following code (which I've changed a bit) and the explanation in blue in a book. I don't understand the use of getch() or other function getche() the book refers to. Could you please comment on this? And what does "\r" stands for? Thanks for all the help.
One function in EXTERN, getachar(), reads characters from the keyboard. It uses the library function getch(), which is like getche() except that it doesn’t echo the character typed to the screen (hence the absence of the final e in the name). A second EXTERN function, putachar(), displays each character on the screen. The effect is that what you type is displayed in the normal way:
I’m typing in this line of text
Code:
// extern.cpp
// demonstrates global variables
#include <iostream>
#include <cstdlib>
#include <conio.h> //for getch()
using namespace std;
char ch = 'a'; //global variable ch
void getachar(); //function declarations
void putachar();
int main()
{
cout << "ch is: " << ch << endl;
while( ch != '\r' ) //main() accesses ch
{
getachar();
putachar();
}
cout << endl;
system("pause");
return 0;
}
//--------------------------------------------------------------
void getachar() //getachar() accesses ch
{
ch = getch();
}
//--------------------------------------------------------------
void putachar() //putachar() accesses ch
{
cout << ch;
}