Exercise 1-22 writes a program that "folds" the longer input lines into shorter two or more lines, after the last non-whitespace before the nth column of the input row. Ensure that the program intelligently handles input lines that are long and that there are no spaces or tabs in front of the columns you have set.
The code is as follows:
#include <stdio.h>//contains information about the standard library. #defineMAXLINE 1000//the maximum number of characters per line is 1000. #defineBR 10//10 characters in a line. intGetlineCharLine[],intmaxline);intMain ()//defines a function named Main, which does not accept parameter values. { intLen; CharLine[maxline]; while(len = getline (line, MAXLINE)) >0) {printf ("%s\n", 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, J; C= i = j =0; while(I < Lim-1&& (c = GetChar ())! = EOF && c! ='\ n') { if(c = ='\ n') {s[i++] =C; } Else if((i-j)% BR +1= = BR)//The line needs to be folded. { if(c! ='\ t'&& C! =' '&& i! = BR)//This character is ignored if the position where you want the line break is a space or a tab. {s[i++] =C; S[i++] ='\ n'; J++; } } Elses[i++] =C; } if(S[i-1] =='\ n') S[i-1] =' /';//if the previous character is a newline, the line break is not performed. ElseS[i]=' /'; returni;}
Personal Understanding:
The main practice is to insert a character into a character array at a location.
C Programming language Exercises 1-22