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