码迷,mamicode.com
首页 > 其他好文 > 详细

//利用指针删除母串中的指定子串

时间:2020-06-21 09:17:32      阅读:62      评论:0      收藏:0      [点我收藏+]

标签:std   指针   string   strlen   图片   inf   运行   main   pre   

//利用指针删除母串中的指定子串 
#include<stdio.h>
#include<string.h>
int fun(char *a,char *b) //函数功能是判断两字符串的首字符相同时,母串是否包含子串 
{
    while(*a==*b&&*a&&*b)
    {
        a++;b++;
    }
    if(*b==0)return 1;
    return 0;
}
void delfun(char *a,char *b) //删除母串中的指定子串 
{
    char *p;
    for(p=a;*p;p++)
    {
        if(fun(p,b))
        {
            strcpy(p,p+strlen(b));
            continue;
        }
    }
}
int main()
{
    char a[100],b[20];
    gets(a);
    gets(b);
    delfun(a,b);
    puts(a);
}

运行结果:

技术图片

//利用指针删除母串中的指定子串

标签:std   指针   string   strlen   图片   inf   运行   main   pre   

原文地址:https://www.cnblogs.com/yanglike111/p/13171326.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!