Exercise 1-17 Write a program that prints all input lines that are longer than 80 characters long.
The code is as follows:
#include <stdio.h>//contains information about the standard library. #defineMaxRow 10//the maximum number of rows is 10 rows. #defineMAXLINE 100//the maximum number of characters per line is 100. intGetLength (Charcs[]);intMain ()//defines a function named Main, which does not accept parameter values. { intc, I, row; CharCs[maxrow][maxline]; //Initializes a character array of 10 rows. for(i =0; i < MaxRow; i++) {cs[i][0] =' /'; } I= row =0; while(Row < MaxRow && (c = GetChar ())! =EOF) { //put each line you enter in the array. if(c! ='\ n') { if(I < MAXLINE-2) {Cs[row][i]=C; I++; } Else{cs[row][maxline-1] =' /'; } } Else { //When the line is changed, the last thought of this row is added '% '. if(I < MAXLINE-2) Cs[row][i] =' /'; //move to the next line. row++; //counter Clear 0. i =0; } } if(row = = MaxRow) {printf ("10 lines have been entered to start the statistics ... \ n"); } //Enter a line with a character greater than 10. for(row =0; Row < MaxRow; row++) { if(GetLength (Cs[row]) >Ten) {printf ("%s\n", Cs[row]); }} 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. }//gets the length of each line. intGetLength (Charcs[]) { inti =0; while(cs[i++]! =' /') ; returni;}
Personal Understanding:
Limit the maximum number of rows to support 10 lines, 100 characters per line, the practice mainly consolidates the use of the character array ' \ s '.
C Programming language Exercises 1-17