/*
函数 strchr()
功 能: 在一个串中查找给定字符的第一个匹配之处/
用 法: char *strchr(char *str, char c);
程序例:
The character r is at position: 12 n
*/
#include <stdio.h>
#include <string.h>
int main(void)
{
char string[15];
char *ptr, c = 'r';
strcpy(string, "This is a string");
ptr = strchr(string, c);
if (ptr)
//printf("1111") ;
printf("The character %c is at position: %d %c/n", c, ptr-(char*)string,ptr[2]);
else
printf("The character was not found/n");
return 0;
}
/*
函数 strstr()
原型:extern char *strstr(char *haystack, char *needle);
用 法: #include <string.h>
功能:从字符串haystack中寻找needle第一次出现的位置(不比较结束符NULL)。
说明:返回指向第一次出现needle位置的指针,如果没找到则返回NULL。
程序例:
The character r is at position: 2 s
*/
#include <stdio.h>
#include <string.h>
int main(void)
{
char string[15];
char *ptr, c = 'r';
strcpy(string, "This is a string");
ptr = strstr(string, "is");
if (ptr)
//printf("1111") ;
printf("The character %c is at position: %d %c/n", c, ptr-(char*)string,ptr[8]);
else
printf("The character was not found/n");
return 0;
#if 0
char *s="Golden Global View";
char *l="lob";
char *p;
// clrscr();
p=strstr(s,l);
if(p)
printf("%s",p);
else
printf("Not Found!");
#endif
getchar();
}