Practice 1-18 Write a program that removes spaces and tabs at the end of each input line and removes rows that are completely blank.
The code is as follows:
#include <stdio.h>//contains information about the standard library. #defineMAXLINE 10//the maximum number of characters per line is 1000. intGetlineCharLine[],intmaxline);intMain ()//defines a function named Main, which does not accept parameter values. { intLen; inti; CharLine[maxline]; while(len = getline (line, MAXLINE)) >0) { intc =0; //loops forward the character array from the back. for(i = len-1; I >=0; i--) { if(Line[i] = ='\ t'|| Line[i] = =' ')//if the last character is a tab, the position is set to. Line[i] =' /'; Else Break;//if the last character is not a tab or a space, the loop stops. } printf ("%s", line); } getchar (); //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. }intGetlineCharS[],intLim) { intc, I; for(i =0; I < Lim-1&& (c = GetChar ())! = EOF && c! ='\ n'; ++i) {s[i]=C; if(c = ='\ n') {S[i]=C; ++i; }} S[i]=' /'; returni;}
Personal Understanding:
The main practice is the Flashback Loop array, and match the last one, if the space or tab is replaced by '.
C Programming language Exercises 1-18