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 !!!