字符串copy函数、字符串查找出现次数函数
来源:互联网 发布:js防水涂料厚度 编辑:程序博客网 时间:2024/06/03 17:31
字符串copy函数
//避免操作空指针以及引入辅助指针变量增强程序的健壮性#define _CRT_SECURE_NO_WARNINGS#include <stdio.h>#include <stdlib.h>#include <string.h>int str_cpy06(char *from, char *to){ char * tmpfrom = from;//避免修改形参 char * tmpto = to; if (from == NULL || to == NULL)//避免操作空指针 return -1; while (*tmpto++ = *tmpfrom++); printf("from:%s\n",from); return 0;}int main(void){ char *src = "abcd"; char buf[64]; str_cpy06(src, buf); printf("buf:%s\n", buf); system("PAUSE"); return 1;}
字符串查找函数
strstr–do-while模型(strstr模型)
#define _CRT_SECURE_NO_WARNINGS#include <stdio.h>#include <stdlib.h>#include <string.h>int getCountDoWhile(char * p_str, char *sub_str, int *ncount){ int ret = 0; char * src = p_str; int tmp_count = 0; if (p_str == NULL || sub_str == NULL || ncount == NULL)//合法性检测 { ret = -1; printf("%s is error:(p_str == NULL || sub_str == NULL || ncount == NULL)\n", __FUNCTION__); return ret; } do{ src = strstr(src, sub_str); if (src != NULL) { tmp_count++; src += strlen(sub_str); } else{ break; } } while (*src != '\0'); *ncount = tmp_count; return ret;}int main(void){ //strstr(str, str2) int ncount = 0; int ret = 0; char *p = "11abcd111122abcd3333322abcd3333322qqq"; ret = getCountDoWhile(p,"abcd",&ncount); if (ret != 0){ printf("func getCountDoWhile() err:%d \n", ret); return ret; } printf("ncount:%d \n", ncount); system("PAUSE"); return ret;}
while模型
#define _CRT_SECURE_NO_WARNINGS#include <stdio.h>#include <stdlib.h>#include <string.h>int getCountWhile(char * p_str, char *sub_str, int *ncount){ int ret = 0; char * src = p_str; int tmp_count = 0; if (p_str == NULL || sub_str == NULL || ncount == NULL)//合法性检测 { ret = -1; printf("%s is error:(p_str == NULL || sub_str == NULL || ncount == NULL)\n", __FUNCTION__); return ret; } while (src = strstr(src,sub_str)){ tmp_count++; src += strlen(sub_str); if (*src == '\0') break; } *ncount = tmp_count; return ret;}int main(void){ //strstr(str, str2) int ncount = 0; int ret = 0; char *p = "11abcd111122abcd3333322abcd3333322qqq"; ret = getCountWhile(p, "abcd", &ncount); if (ret != 0){ printf("func getCountWhile() err:%d \n", ret); return ret; } printf("ncount:%d \n", ncount); system("PAUSE"); return ret;}
阅读全文
0 0
- 字符串copy函数、字符串查找出现次数函数
- php 查找字符串出现次数函数介绍
- 编写函数查找字符串中子字符串出现的次数
- PHP查找子字符串出现次数的函数
- 查找字符串出现次数
- 查找字符串出现次数
- C语言程序设计——在字符串S1查找字符串S2出现次数的函数
- 查找指定字符串出现次数
- 查找字符串中子字符串出现次数
- 字符串copy函数
- 提供任意字符串,js写一个函数能够查找字符串中出现最多的次数的字符及其个数。
- 提供任意字符串,请构造一个函数能够查找字符串中出现最多的次数和个数
- 【11g】使用REGEXP_COUNT函数统计字符串出现的次数
- PHP函数 替换指定出现次数的子字符串
- 使用REGEXP_COUNT函数统计字符串出现的次数
- 【11g】使用REGEXP_COUNT函数统计字符串出现的次数
- 【11g】使用REGEXP_COUNT函数统计字符串出现的次数
- 从字符串中查找字符出现次数
- RN 基础
- 【安全牛学习笔记】思路、身份认证方法、密码破解方法、字典
- 如何正确地写出单例模式
- OpenCV 轮廓检测《转自雷霄骅的文章》
- VS2013无法嵌入互操作类型“Shell32.ShellClass"的解决方案
- 字符串copy函数、字符串查找出现次数函数
- IntentFilter匹配规则-交朋友
- laravel框架中前端如何使用csrf
- pytorch安装----CPU版的
- 基于Java本地文件读写操作的用户登录注册验证模块
- Oracle Bug和PSU的集成关系
- GC 垃圾回收算法,新生代,老年代,持久代
- Android之json复杂数据解析
- 设计模式