C Delete String 1 string 2

Source: Internet
Author: User

#include <stdio.h>
#include <string.h>
void Main ()
{
Char s1[1000],s2[100],b[100];
int i,j,k,len1,len2;
Gets (S1);
Gets (S2);
Len1=strlen (S1);
Len2=strlen (S2);
for (i=0,k=0;i<len1;i++)
{
for (j=0;j<len2;j++)
if (S1[i+j]!=s2[j]) break;
if (J&GT;=LEN2)
{
b[k]=i+1; B[k] is where S2 appears in S1
k++; K is the number of occurrences of S2 in S1
}
}
printf ("%d\n", K);
for (i=0;i<k;i++)
printf ("%d", b[i]);
printf ("\ n");


for (j=0;j<k;j++)//Remove S2 in S1
for (i=0;i<len2;i++)
s1[b[j]-1+i]= ' * ';
for (i=0;i<len1;i++)
if (s1[i]!= ' * ')
printf ("%c", S1[i]);
printf ("\ n");
}

Copyright notice: This article Bo Master original articles, blogs, without consent may not be reproduced.

C Delete String 1 string 2

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.