Function prototype: int getch (void);
Function: Read a character from the console, but don't display it on the screen.
Function returns: characters read.
(2) Rand ()
Function prototype: int rand (void);
Function: a random function that generates a random integer between 0 and 32767 (between 0 and 0x7fff).
Function return: random integer
Belonging documents:
(3)srand()
Function prototype: void srand (unsigned seed);
Function: This function is used in conjunction with the rand random function to generate the initial occurrence data of random numbers.
Parameter description: seed is an unsigned integer.
Belonging documents:
(4) Time ()
Function prototype: time_t time(time_t *timer)
Function: Get the calendar time of the machine or set the calendar time.
Function returns: machine calendar time.
Parameter description: when timer=NULL, the machine calendar time is taken; When timer= time value, it is used to set the calendar time.
Time_t is a long integer.
Belonging documents:
(5)'\b' realizes backspace, that is, the current cursor moves back one space.
(6)'\a' rings, that is, the computer will beep when it is running.
(7) The acquisition method of random values ranging from A to B (including B): rand ()% (b-a+1)+a; # include & ltstdio.h & gt
# include & ltconio.h & gt//header file required by getch () function.
# include & ltstdlib.h & gt// Header file required by random function.
# include & lt time.h & gt//header file required by time () function.
Void clear(void)// This function is used to clear the current line.
{
printf(\ r \ r);
}
Invalid start (invalid)
{
Puts (this is a simplified version of the word elimination game, which can be seen by people who can't program images);
Puts (because there is no database, the word is analog. );
Puts (press any key to start, press Esc to end, press tab to start again:);
Put option (once you make a mistake, an audible warning will be issued, and you must re-enter it. );
Puts (press any key to start and press Esc to end:);
If('' == getch()) // Press Esc to end.
{
Exit (1);
}
}
int main()
{
char*c_rand,* c _ input
int i,j,N,N,space,N _ rand
start();
Printf(\r How many letters do you want to erase? (Enter the number (1-9));
n = getch();
n = n-' 0 '; //Convert the input characters into integers.
clear(); //Clear the current line
If (! ((N & gt= 1。 & ampn < = 9) || n = = 27)//27 is the ASII value of the Esc key.
{
Printf(\r range error, please start again:);
getch();
Exit (1); //Abnormal exit
}
If (n==27)
Returns 0;
srand(time(NULL)); //Used to initialize random functions.
c _ rand =(char *)malloc(N+ 1);
c _ input =(char *)malloc(N+ 1);
while( 1)
{
N _ rand = rand()% N+ 1; //Realize any defined word length.
for(I = 0; I<N _ randi++)
{
c_rand[i]=(rand() ==0)? (rand ()&+'a'): (rand ()&; +' a '); //Take any letter.
}
c _ rand[N _ rand]= ' \ 0 ';
//The following four lines of code realize the random appearance of word positions.
space = rand()% 50;
putchar(' \ r ');
for(I = 0; I< space; i++)
putchar(“”);
printf(%s,c _ rand);
for(I = 0; I<N _ randi++)
{
c _ input[I]= getch(); //User input
If(c _ input[I]=' ')// stands for Esc key.
Break;
//The following five lines of code realize the effect of letters disappearing.
putchar(' \ r ');
for(j = 0; J< space; j++)
putchar(“”);
for(j = 0; j & lt= I; j++)
putchar(“”);
if(c_input[i]! =c_rand[i])
{
I =- 1;
putchar(' \ a ');
//Reproduction effect of the following four lines of code letters
putchar(' \ r ');
for(j = 0; J< space; j++)
putchar(“”);
printf(%s,c _ rand);
}
}
If(c _ input[I]=' ')// stands for Esc key.
Break;
}
Free (c _ rand);
Free (c _ input);
Returns 0;
}