C Programming language Exercises 1-17

Source: Internet
Author: User

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

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.