编写一个函数 char *my_strnchr(char const *str,int ch,int which)
来源:互联网 发布:万宝瑞华人才管理 知乎 编辑:程序博客网 时间:2024/05/16 05:41
/**************************************** * File Name : my_strnchr.c * Creat Data : 2015.1.22* Author : ZY *****************************************/ /*编写一个函数char *my_strnchr(char const *str,int ch,int which)第三个参数指定ch字符在str字符串中第几次出现。例如,如果第三个参数为1,这个函数的功能就和strchr完全一样。如果第三个参数为2,这个函数就返回一个指向ch字符在str字符串中第二次出现的位置的指针。*/#include <stdio.h>#include <assert.h>char *my_strnchr(char const *str,int ch,int which){int count = 0;assert(str);while(*str){if( ch == *str ){count++;if( count == which ){return str;}}*str++;}return NULL;}int main() { char *arr="123452";int a = '2';int count = 1;if( NULL == my_strnchr(arr,a,count) ) { printf("Can't find the character %c !\n",a); } else { printf("Find the character %c !\n",a); printf("%p\n",my_strnchr(arr,a,count)); } return 0; }
0 0
- 编写一个函数 char *my_strnchr(char const *str,int ch,int which)
- 编写一个函数 char *my_strrchr(char const *str,int ch)
- C和指针之字符串编程练习8实现char *my_strnchr(char const *str, int ch, int which)
- int atoi(const char * str)
- int strlen(const char *str)
- char * strchr (const char *str, int c);
- 编写函数int count_number_string(char str[])和函数int maxnum_string(char str[])
- 为函数原型编写函数定义: int ascii_to_integer(char *str);
- int atoi(const char *str)库函数实现
- C和指针之字符串实现my_strrchr(char *str, int ch)的函数
- C++学习笔记:int sprintf ( char * str, const char * format, ... );
- 编写一个函数 int count_chars(char const *str,char const *chars) 函数应该在第一个参数中进行查找, 并返回匹配第二个参数所包含的字符的数量。
- int atoi(char *str) 函数实现
- atoi函数 int m_atoi(char* str)
- int const * 、const int *、int *const、const char **与char **
- int atoi(const char*)
- char*const*(*next)(int)
- int 转str or char*
- [gdb]函数堆栈乱掉的解决办法
- 在PhpStorm中配置XDebug调试PHP代码
- Dialog去除边框代码
- uml of linux
- 最长递增子序列 O(n^2) 与 O(nlogn)
- 编写一个函数 char *my_strnchr(char const *str,int ch,int which)
- dmalloc的使用
- 用笔记本远程访问连接在路由器上的树莓派
- Javascript:表单验证(验证空值/邮箱格式)
- JAR文件
- POJ 2385 Apple Catching
- C中如何调用C++函数
- iOS之KxMenu第三方的使用
- TypeError: $(...).ajaxSubmit is not a function