编写程序将"hello-NOworld"变成"hello-world"
2015-10-28 15:00
405 查看
从字符串str"hello-NOworld"中删除字符串sub"NO"
如果找到并成功删除返回1,不然那返回0。
本文出自 “痕迹” 博客,请务必保留此出处http://wpfbcr.blog.51cto.com/10696766/1707266
如果找到并成功删除返回1,不然那返回0。
#include<stdio.h> #include<assert.h> int my_substr(char *str,const char*sub) { assert(sub); char *cp1_str = str; char *cp2_str = str; const char *cp_sub = sub; while (*str) { cp1_str = str; while (*sub) { if (*sub == *cp1_str) { sub++; cp1_str++; } else { break; } } if (*sub == '\0') { while (*cp1_str) { *str = *cp1_str; cp1_str++; str++; } *str = '\0'; return 1; } sub = cp_sub; str++; } return 0; } int main() { char str[] = "hello-NOworld"; char *chars = "NO"; int ret = my_substr(str, chars); printf("str=%s,ret=%d", str, ret); }输出结果为,str=hello-world,ret=1
本文出自 “痕迹” 博客,请务必保留此出处http://wpfbcr.blog.51cto.com/10696766/1707266
相关文章推荐
- 找工作笔试面试那些事儿(1)---C,C++基础和编程风格(1)
- metro应用简述
- Hessian矩阵
- OnLongClickListener长按事件设置墙纸
- Android Studio系列教程六--Gradle多渠道打包
- spring+jsonp
- Android Intent 使用整理
- INDY idhttp Post用法
- ios测试基础三:xcode对iOS项目打包与证书配置
- Java内存优化和性能优化的几点建议
- Instrument Driver (iOS下的自动化测试)
- 关于iPhone手机如何导入本地音乐
- Linux系统虚拟主机网站访问出现500 Internal Server Error报错常见原因
- LinuxCentos6安装中文输入法
- nyoj 1058 部分和问题
- 回到顶部特效
- SQL数据库优化步骤大全
- PCA
- DP-HDU-1078-FatMouse and Cheese
- Carthage使用(解决部分Swift运行时的问题)