#include <stdio.h>
#include <string.h>
#include <stdio.h>
#include <string.h>
//#define NULL (void *)0
int main(void)
{
char s1[] = "hello world itcast";
char key = 'o';
char *p, *q;
q = s1;
while ((p = strchr(q, key)) != NULL) {
printf("%p\n", p);
printf("%s\n", p);
q = p+1;
}
return 0;
}
此函数没有在dest数组里默认加'\0',需要手动自己加。注意。
#include <stdio.h>
#include <string.h>
//#define NULL (void *)0
int main(void)
{
char s1[] = "hello world itcast";
char key = 'o';
char *p, *q;
q = s1;
while ((p = strchr(q, key)) != NULL) {
printf("%p\n", p);
printf("%s\n", p);
q = p+1;
}
return 0;
}
本文展示了一个使用C语言的程序示例,该程序通过strchr函数遍历字符串helloworlditcast来查找所有出现的字符'o'的位置。每个找到的'o'的位置及其之后的子串都会被打印出来。
1017

被折叠的 条评论
为什么被折叠?



