删除子串

来源:互联网 发布:e63诺基亚怎么下载软件 编辑:程序博客网 时间:2024/06/05 17:47
//输入字符串A和B,将A中和B字符串相同的子串删除,并输出#include <stdio.h>#include <string.h>void delete(char *str,char *ptr,char *result) //删除子串{char *p1 = str;                          //字符串Achar *p2 = ptr;                          //字符串B//int  count = 0;//int flag = 0;int n1 = strlen(str);int n2 = strlen(ptr);if(str == NULL || ptr == NULL){    return -1;}while(*p1 != '\0'){if(*p2 == '\0'){*result -= n2;            p2 = ptr;continue;}*result = *p1;if(*p1 == *p2){    p2++;p1++;}*result = '\0';}/*while(*p1 != '\0'){count = 0;p2 = ptr;        while(*p1 == *p2){p1++;p2++;count++;}if(*p2 != '\0'){ p1 = p1 -count;}else{flag = 0;}*result = *p1;result++;p1++;}    *result = '\0';}*/int main(){    char str[100] = {0};char ptr[100]  = {0};char result[100] = {0};    printf("Please input string A:");scanf("%s",str);printf("Please input string B:");scanf("%s",ptr);delete(str,ptr,result);printf("%s",result);/*if(ret == -1){    printf("error!");}else{printf("%s",result);    }*/    return 0;}

0 0
原创粉丝点击