c语言程序设计进阶week3:删除字符串中的子串(字符串与指针的完美结合)
2017-03-14 11:30
459 查看
题目来源自mooc:C语言程序设计进阶,仅供个人学习参考使用
#include <stdio.h>
#include <string.h>
int main(){
char s1[85], s2[85];
char *p;
char temp[85];
scanf("%s",&s1);
scanf("%s",&s2);
while((p=strstr(s1,s2)) != NULL) { //在s1和s2字符中找不到相同元素时停止,strstr字符串中招字符串
*p = '\0';//把s1自与s2相等的头处改为\0,截断
strcpy(temp , p+strlen(s2));//把p向后延到s1与s2相等的那段末尾处拷贝到 strcpy拷贝字符串
strcat(s1, temp );//把temp 接在s1后面
}
puts(s1);
return 0;
}
这一题很有意思
相关文章推荐
- C和指针之删除字符串第一次出现的子串
- C语言程序设计进阶-Chap02-指针与字符串
- 指针解决字符串删除子串
- 字符串-02. 删除字符串中的子串(20)
- 删除字符串中的子串
- 删除字符串中的子串
- 删除字符串中的子串
- 在字符串中查找子串,删除子串
- 第十七周项目2-用指针玩字符串(删除)
- 华为机试 删除字符串中所有给定的子串
- 删除字符串中特定的子串
- Exe7 删除字符串中指定的字符 (还有有问题——指针的问题)
- C语言字符串操作--删除子串
- 华为机试-删除字符串中所有给定的子串
- 删除原字符串中所有匹配的子串,并返回匹配的子串个数
- 从字符串中删除指定子串或指定元素
- 字符串删除子串
- 完美的C#字符串删除函数,可以匹配多个进行删除。
- 删除 字符串中‘*’号 两端的除外。指针h、p分别指向第一个和最后一个字符
- 华为机试 删除字符串中所有给定的子串