strchr和strstr函数

函数名: strchr
功 能: 在一个串中查找给定字符的第一个匹配之处\
用 法: char *strchr(char *str, char c);
#include <string.h>
#include <stdio.h>
int main(void)
{
char string[15];
char *ptr, c = 'i';
strcpy(string, "This is a string");
ptr = strchr(string, c);
if (ptr)
printf("The character %c is at position: %d\n", c, ptr-string
+1);
else
printf("The character was not found\n");
return 0;
}

 

包含文件:string.h
  函数名: strstr
  函数原型:extern char *strstr(char *str1, char *str2);
  功能:找出str2字符串在str1字符串中第一次出现的位置(不包括str2的
串结束符)。
  返回值:返回该位置的指针,如找不到,返回空指针。

 

posted @ 2012-04-13 09:36  加拿大小哥哥  阅读(613)  评论(0编辑  收藏  举报