current position:Home>The following program (function) deletes the characters exactly the same as the string S2 in the string S1, such as S1: China S2: in, and the result is cha

The following program (function) deletes the characters exactly the same as the string S2 in the string S1, such as S1: China S2: in, and the result is cha

2022-02-02 23:22:29 CSDN Q & A

  1. The following procedure ( function ) Delete the string S1 And string S2 Exactly the same characters , Such as s1: CHINA s2: IN, The result is CHA.

It is required to use the code in the red part, including pointer ( Or symbolic address ) Statement substitution .

#include<stdio.h>

#include<string.h>

int fitting(int ind,char a[],char b[]) { // perhaps _______

int num=0;  int m=strlen(a);  intn=strlen(b);for (int k=0;k<n;k++)      if (a[ind+k]!=b[k])  return 0;       //  perhaps ______ return  1; 

}

int ss(char a[],char b[]){

int k=0,t=0;

for (int i=0;a[i]!='\0';){ // perhaps _______

      if (fitting(i,a,b))           i+=strlen(b);           else  { a[t++]=a[i]; i++;}               //  perhaps _______    }    a[t]='\0';  return 0;

}

int main(){

char a[]="china ina in"; char b[]="is";

printf(a);printf("\n");

ss(a,b); // perhaps _______

printf(a);printf("\n");

return 0;




Refer to the answer 1:
#include <stdio.h>#include<string.h>squeeze(char* s1, const char* s2){    int i=0;    int j=0;    for(i=0; i<strlen(s1); i++)        for(j=0; j<strlen(s2); j++)        {            if(s1[i]==s2[j])              s1[i]=' ';           }}int main(){    char a[100],b[100];    printf(" Please enter s1:");    scanf("%s",&a);    printf(" Please enter s2:");    scanf("%s",&b);    squeeze(a,b);    printf(" After deleting :%s\n",a);    return 0;} 



Refer to the answer 2:

copyright notice
author[CSDN Q & A],Please bring the original link to reprint, thank you.
https://en.primo.wiki/2022/02/202202022322271086.html

Random recommended