PAT 10-2 remove the substring from the string, pat10-2

Source: Internet
Author: User

PAT 10-2 remove the substring from the string, pat10-2

Today, I sent an incomplete code, but the dual-use case failed. I couldn't see the problem at the moment.

/* Enter two strings S1 and S2 on June 4,. Delete All substrings S2 in string S1, that is, the result string cannot contain S2. Input Format: enter two non-empty strings of no more than 80 characters ending with a carriage return in the two lines, corresponding to S1 and S2. Output Format: output the result string after deleting all substrings S2 in string S1 in one row. Input example: Tomcat is a male ccatatcat output example: Tom is a male */# include <stdio. h> # include <string. h> int main () {char S1 [81], S2 [81]; gets (S1); gets (S2); char * p; int len; len = strlen (S2); p = strstr (S1, S2); while (p) {strcpy (p, p + len); p = strstr (S1, S2 );} printf ("% s \ n", S1); return 0 ;}

I modified it twice on the 5 th. I have compared a program passed through, which is different from strcpy. Why is it wrong here? Ask for advice !!!

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.