G ++ compile the program to import the getch () function, getch
Note: In ubuntu, G ++ compiles the C ++ program to import the getch () function (the program will continue to run only after a value is input by the standard function, no <conio. h> function library, so you need to import <curses. h> and use g ++-o test-lncurses test. cpp compilation, if the error still persists, use sudo apt-get install libncurses5-dev to install the header file.
C language getch () Problem
Getch (); is not a function in Standard C and does not exist in C .!!
Header file: conio. h
We recommend that you replace it with getchar () or another type.
Getch ()
Getch ():
Header file: conio. h
Function purpose: Read a character from the console, but it is not displayed on the screen.
Function prototype: int getch (void)
Returned value: read characters
For example:
Char ch; or int ch;
Getch (); or ch = getch ();
Use getch (); wait for you to press any key, and then continue to execute the following statement;
Use ch = getch (); after you press any key, assign the ASCII code corresponding to the key character to ch, and then execute the following statement.
Easy to error: 1. the header file is conio. h. Instead of stdio. h.
2. Call initscr () before use, and call endwin () at the end (). Otherwise, the function does not contain any characters.
The returned results.
Getch (); is not a function in Standard C and does not exist in C. So pay attention to the portability of the program when using it. Chinese C language beginners often use getch (); to pause the program and do not know the function source. We recommend that you use getchar (); (if possible) to replace this function or change a compiler.
When the C program is running, the program will flash through and add getch ();
Different functions used by compilers are different.
The landlord can use system ("pause"); instead of getch ();
# Include <stdio. h>
Int main ()
{
Int n, I, sum;
Printf ("enter a natural number :");
Scanf ("% d", & n );
For (I = 1, sum = 0; I <= n; I ++)
Sum + = I;
Printf ("sum of consecutive natural numbers from 1 to % d: % d \ n", n, sum );
System ("pause ");
Return 0;
}