从键盘输入父串,子串,要求删除父串中的子串。
来源:互联网 发布:芒果tv php视频解析 编辑:程序博客网 时间:2024/06/04 01:10
如:
父串:“hellosdhellodsfhellohello”
子串:“hello”
要求删除父串中的hello。
#include <stdio.h>#include <string.h>#define MAX_SIZE 1024int my_strncmp(char *s1, char *s2, int len){ int i; for(i = 0; i < len; i++) { if(*(s1 + i) != *(s2 + i)) { return -1; } } return 0;}char *delete_aim_str(char *src, char *delete){ int i; int d_len = strlen(delete); int s_len = strlen(src); char *dest = src; while(*src != '\0') { if(my_strncmp(src,delete,d_len) == 0) { for(i = 0; i < s_len - d_len; i++) { *(src+i) = *(src + d_len+i); } } src++; } return dest;}int main(){ char src[MAX_SIZE]; char delete[MAX_SIZE]; printf("Please input string src:\n"); scanf("%s",src); printf("Please input string to be deleted:\n"); scanf("%s",delete); char *result = delete_aim_str(src,delete); printf("The result is:\n%s\n",result); return 0;}
0 0
- 从键盘输入父串,子串,要求删除父串中的子串。
- 删除字符串中的子串
- 删除字符串中的子串
- 删除字符串中的子串
- 删除字符串中的子串
- 删除字符串中的子串
- 删除字符串中的子串
- 删除字符串中的子串
- 删除字符串中的子串
- 删除字符串中的给定子串
- <记录>删除字符串中的子串
- 删除字符串中的子串(20)
- 删除字符串中的特定子串
- 删除指定字符串中的子串
- 5-29 删除字符串中的子串
- 删除字符串中的子串 PAT
- 【C++】删除字符串中的子串
- 删除字符串中的指定子串
- intellij idea eclipse mac 设置java编码格式为google - style
- (十四)桥接模式详解(都市异能版)
- KDB应用指南
- C#中如何调用动态链接库DLL
- 单例模式的Java泛型实现方式
- 从键盘输入父串,子串,要求删除父串中的子串。
- c++丑数判断
- 八皇后(原创)
- 集合
- Scrapy源码分析(三):信号管理器SignalManager
- HDU2049_不容易系列之(4)——考新郎
- 数据库日常管理常用sql脚本
- Android基础
- (十五)建造者模式详解(都市异能版)