Enter multiple lines of information in the terminal, locate the line containing "Ould", and print the row

Source: Internet
Author: User

Enter multiple lines of information in the terminal, locate the line containing "Ould" , and print the row.

Such as:

Au,love could you and I with fate conspire

To grasp this sorry scheme of things entire,

Would not we shatter it to bitd–and then.

In the terminal output the above text, output

Au,love could you and I with fate conspire

Au,love could you and I with fate conspire

To grasp this sorry scheme of things entire,

Would not we shatter it to bitd–and then.

Would not we shatter it to bitd–and then.

Create a function to enter multiple lines of string.

Establish a function to simulate the STRSTR function function to determine whether the input line of information contains "Ould", that is, "Ould" is not a substring of the row string.

The code is as follows:

 #include <stdio.h> #include <stdlib.h> #include <assert.h># Define rom 1000int input (char *str,int list) {Char ch=0;int i=0;while ( list--) && (Ch=getchar ())!=eof&&ch!= ' \ n ')     //note the number of limits per line and valid characters, encountered end input {str[i++] =ch;} if (ch== ' \ n ') {str[i++]= ' \ n ';//Enter only one character ' \ n ', save ' \ n '}str[i]= '; return i;} Int match (CHAR&NBSP;*DEST,CHAR&NBSP;*SRC)//Simulate the function of strstr function {char *p=dest;//save each start match position assert (dest); ASSERT (SRC), while (*p) {CHAR&NBSP;*S1=P;CHAR&NBSP;*S2=SRC;//S1 and S2 are the positions to which the actual match is moved while (*s1&&*s2&& (* S1==*S2) {s1++;s2++;    if (*s2== ')//If S2 matches, it means that SRC is dest substring          return 1;} p++;} return 0;} Int main () {char str[rom];char arr[]= "Ould"; while (input (str,rom-1)) {if (Match (Str,arr)) {printf ("% S ", str);}} System ("pause"); return 0;} 

This article is from the "Materfer" blog, make sure to keep this source http://10741357.blog.51cto.com/10731357/1711100

Enter multiple lines of information in the terminal, locate the line containing "Ould", and print the row

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.