C language print mode matching row exercises

Source: Internet
Author: User

# Include <stdio. h> # include <string. h> /************************************* the C programing language (second edition) "Small exercise *******************************/int getline (char *, int);/* find function: print all rows that match the pattern of the first specified parameter */int main (int argc, char * argv []) {char line [1000]; int found = 0; printf ("input a line:"); if (argc! = 2) printf ("error message: find partten! \ N "); else while (getline (line, 1000)> 0) if (strstr (line, argv [1])! = NULL) {printf ("% s", line); found ++;} return found;}/* getline function: get the row */int getline (char * line, int MAXLINE) {char c; int I; for (I = 0; I <MAXLINE-1 & (c = getchar ())! = EOF & c! = '\ N'; ++ I) line [I] = c; if (c =' \ n') {line [I] = c; ++ I ;} line [I] = '\ 0'; return I ;}

 

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.