Practice 1-10 Write a program that copies the input to the output, replaces the lifting tab with \ T, replaces the fallback character with the \b, and replaces the backslash with \ \. This allows you to display tab and fallback characters in a visible way.
The code is as follows:
#include <stdio.h>//contains information about the standard library. #include<conio.h>intMainvoid)//defines a function named Main, which does not accept parameter values. {printf ("====== replaces the tab characters in the input with \ t, the return character is replaced by \b, and the backslash is replaced with \\======\n"); //int C; //GetChar () is cached, so \b are directly functioning, so the program does not display ' \b '. /*while ((c = GetChar ()) = EOF) {//Here the character is judged and replaced by If-else. if (c = = ' \ t ') printf ("\\t"); else if (c = = ' \b ') printf ("\\b"); else if (c = = 8) printf ("\\b"); else if (c = = ' \ \ ') printf ("\\\\"); else Putchar (c); }*/ //In This example, when the user enters a return event, the input is terminated, the characters are replaced immediately, and the input is not copied to the output program. /*while ((c = getch ())! =) {if (c = = ' \ t ') printf ("\\t"); else if (c = = ' \b ') printf ("\\b"); else if (c = = ' \ \ ') printf ("\\\\"); else Putchar (c); }*/ //Getch (); //prevent the console from flashing through, you need to accept any characters after you close the console. //return 0; //returns a shape to the execution environment, and 0 represents a successful execution. //This topic involves the control of the virtual terminal, the program needs to use a specific API to get backspace. //References:http://www.zhihu.com/question/21658256/answer/18986712 /*int ch; do {ch = _getch (); printf ("%c\n", ch); } while (1);*/ //return 0; //The above code is key to the _getch () function. Reference _getch, _getwch}
Personal Understanding:
The fallback character in this topic has not been implemented according to the requirements of the topic, pending processing.
When you use the GetChar () function, the type fallback immediately takes effect on the buffer and eventually does not get the fallback character.
When you use Getch (), you get a fallback character, but you do not complete the exercise to copy the input to the output .
C Programming language Exercises 1-10