Practice 1-16 Modify the main program of the program that prints the longest line of text, main, so that it can print the length of any length of input lines and print as much text as possible.
The code is as follows:
#include <stdio.h>//contains information about the standard library. #defineMAXLINE 10intGetlineCharLine[],intmaxline);intMain ()//defines a function named Main, which does not accept parameter values. { intLen; intMax; CharLine[maxline]; while(max = Getline (line, MAXLINE)) >0) {printf ("The number of characters entered for the line is:%d. Content is%s\n", Max, line); } printf ("The program ends. "); 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; J=0; for(i =0; (c = GetChar ())! = EOF && c! ='\ n'; ++i) {if(I <= Lim-2)//if the array has one remaining to fill, the characters are not placed in the array. S[i] =C; ++j;//but the line character counter is still +1. } if(J > Lim) S[lim-1] =' /';//if the input character length is greater than the array length, the last digit of the array is written to ' \ s '. ElseS[i +1] =' /';//Otherwise, a valid character is written to ' \ s '. returnJ;}
Personal Understanding:
The main purpose of the exercise is to understand the "+" after the effective bit in the array of char types.
C Programming language Exercises 1-16