ITeye博客

C++ strchr 截取字符串,在协议解析中判断字符很有用

mylove2060 · 2011-07-27 18:55 · C++学习笔记 All · 编程语言 · Markdown

#include const char * strchr ( const char * str, int character ); char * strchr ( char * str, int character ); [code="c++"] /* strchr example */ #include #include 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; } /* 输出结果 Looking for the 's' character in "This is a sample string"... found at 4 found at 7 found at 11 found at 18 */ [/code]

评论(0)

暂无评论。

评论功能维护中,当前仅展示历史评论。