代码;
#include<stdio.h>
#include<string.h>
const char *s1="Happy New Year!";
const char *s2="Year";
const char *s3="pye HwNa";
char *p;
int main()
{
p=strchr(s1,'a');
printf("在字符串s1中首次出现字母'a'的位置是:");
p!=NULL?puts(p):puts("无");
p=strrchr(s1,'a');
printf("在字符串s1中最后一次出现字母'a'的位置是:");
p!=NULL?puts(p):puts("无");
printf("字符串s1从首字符开始不包括字符串s2所含字符的分段长度是: %d\n",
strcspn(s1,s2));
printf("字符串s1从首字符开始只包括字符串s3所含字符的分段长度是: %d\n",
strspn(s1,s3));
p=strpbrk(s1,s2);
printf("字符串s2中任意字符出现在是s1中的位置是: ");
p!=NULL?puts(p):puts("无");
p=strstr(s1,s2);
printf("字符串s2出现在字符串s1中的位置是:");
p!=NULL?puts(p):puts("无");
}
运行: