C Programming language Exercises 1-16

Source: Internet
Author: User

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

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.