Write a program to achieve the replacement string,

 

1: Title

Kin write a program to achieve the replacement string, the program must contain similar function replace (char * s, char * t, char "u), to realize the function string s occurs in all sub-string string replace t u, and

And the number of sub-strings is replaced outputting replacement. If s does not contain substring t, the system outputs: t does not satisfy the conditions of the substring. For example: replace ( "java programming", "java", "c"); the output

e programming, 1 ": replace (" java programming "," python "," c "); the output" condition is not satisfied substring python ".main realized mainly from the function keyboard s, t, u three characters string,

And realize the call to replace function.

achieve:

#include <stdio.h>
#include <string.h>
 
int k=0;
char *strrpc(char *str,char *oldstr,char *newstr){
    char bstr[strlen(str)];
    memset(bstr,0,sizeof(bstr));
 
    for(int i = 0;i < strlen(str);i++){
        if(!strncmp(str+i,oldstr,strlen(oldstr))){
            strcat(bstr,newstr);
            i += strlen(oldstr) - 1;
            k++;
        }else{
            strncat(bstr,str + i,1);
        }
    }
 
    strcpy(str,bstr);
    return str;
}

int main(void)
{
    char s[100];
    char t[100];
    char u[100];
    char copy[100];
    scanf("%s%s%s",s,t,u);
    strcpy(s, copy);
    //strrpc(str,"java","c");
    strrpc (S, T, U);
     IF (strcmp (S, Copy) == 0 ) { 
        the printf ( " did not satisfy the conditions S% " , T); 
    } the else { 
        the printf ( " % S% D " , S, K); 
    } 
    return  0 ; 
}

Guess you like

Origin www.cnblogs.com/dgwblog/p/12127364.html