strchr函数
来源:互联网 发布:哪个网络播放器最好用 编辑:程序博客网 时间:2024/06/06 16:26
function
<cstring>
strchr
const char * strchr ( const char * str, int character ); char * strchr ( char * str, int character );
Locate first occurrence of character in string
Returns a pointer to the first occurrence of character in the C string str.The terminating null-character is considered part of the C string. Therefore, it can also be located in order to retrieve a pointer to the end of a string.
Parameters
- str
- C string.
- character
- Character to be located. It is passed as its int promotion, but it is internally converted back to char for the comparison.
Return Value
A pointer to the first occurrence of character in str.If the character is not found, the function returns a null pointer.
Portability
In C, this function is only declared as:char * strchr ( const char *, int );
instead of the two overloaded versions provided in C++.
Example
1234567891011121314151617
/* strchr example */#include <stdio.h>#include <string.h>int main (){ char str[] = "This is a sample string"; char * pch; printf ("Looking for the 's' character in \"%s\"...\n",str); pch=strchr(str,'s'); while (pch!=NULL) { printf ("found at %d\n",pch-str+1); pch=strchr(pch+1,'s'); } return 0;}
Output:
Looking for the 's' character in "This is a sample string"...found at 4found at 7found at 11found at 18
0 0
- strchr函数
- strchr() 函数
- strchr函数
- strchr函数
- strchr函数
- strchr函数
- strchr 函数
- strchr函数
- strchr函数
- strchr函数
- strchr函数
- strchr函数
- strchr函数
- 函数strchr
- strchr函数
- strchr函数
- strchr函数
- strchr函数
- Python基础--dict
- 读书笔记:Tutorial of React.JS
- 保护果实 【 数学几何】+【贪心】
- JNI中jstring 与 const char* 的转换
- Three.js进阶篇之5
- strchr函数
- 递归的函数
- LeetCode 537. Complex Number Multiplication
- 【Linux】Linux下的find命令
- Hibernate用户手册:2.1 领域模型以及映射类型
- 汉诺塔系列1
- LeetCode-3. Longest Substring Without Repeating Characters
- Ubuntu以root权限运行IDEA
- C++的new与JAVA的new