C language. Enter multiple lines of information on the terminal to find the lines containing the "could" and print and modify the lines.

Source: Internet
Author: User

C language. Enter multiple lines of information on the terminal to find the lines containing the "could" and print and modify the lines.

# Define _ CRT_SECURE_NO_WARNINGS 1 # include <stdio. h> # include <assert. h> # include <stdlib. h> # define MAX 1000int getline (char * line, int limit) {int ch = 0; int I = 0; while (limit -- & (ch = getchar ())! = EOF) & (ch! = '\ N') {line [I ++] = ch;} if (ch =' \ n ') {line [I ++] = '\ n';} line [I] =' \ 0'; return I;} char * my_strstr (char * arr1, char * arr2) {assert (arr1); assert (arr2); char * p = arr1; char * s1 = p; char * s2 = arr2; while (* s1! = '\ 0') {s1 = p; s2 = arr2; while (* s1! = '\ 0') & (* s2! = '\ 0') & (* s1 = * s2) {s1 ++; s2 ++;} if (* s2 =' \ 0 ') {return p;} p ++;} return NULL;} int main () {char * p = "ocould"; char line [MAX] = {0 }; while (getline (line, MAX-1) {if (my_strstr (line, p) {printf ("% s \ n", line );}} system ("pause"); return 0 ;}

 

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.