Practice 1-9 Write a program that copies the input to the output and replaces it with a single space in a contiguous number of spaces.
The code is as follows:
#include <stdio.h>//contains information about the standard library. intMain ()//defines a function named Main, which does not accept parameter values. {printf ("====== will enter multiple spaces with a single space instead of ======\n"); intC, Space; while((c = GetChar ())! =EOF) { if(c! =' ') Putchar (c);//If the character entered is not a space, the output. Else { //If you enter a space, you see if the last character entered is a space, or if it is not, the output. if(Space! =' ') Putchar (c); } //This is where you save this input to the space variable. The next loop is validated as the last input. Space =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. }
Personal Understanding:
The practice is to record the last character entered, and the If-else determines if the character is a space and the last input is a space, the character is not displayed.
C Programming language Exercises 1-9