/*************************************************************************
> File Name: my_strchr.c
> Author:
> Mail:
************************************************************************/
#include<stdio.h>
char * my_strchr(char * a , char ch)
{
char *str = a;
while(*a)
{
a++;
}
while(a-- != str && *a != ch);
if(*a == ch)
return a;
return NULL;
}
int main(int argc, char argv[])
{
char *a = "www.baidu.com";
char ch = '.';
printf("%s\n",a);
printf("%s\n",my_strchr(a,ch));
}
> File Name: my_strchr.c
> Author:
> Mail:
> Created Time: Mon 12 Jan 2015 02:09:29 PM CST
Finds the last occurrence of ch in string. The terminating null character is used as part of the search.
查找在字符串中最后一次出现字符’ch’的位置。如果str中存在字符ch,返回出现ch的位置的指针;否则返回NULL。
************************************************************************/
#include<stdio.h>
char * my_strchr(char * a , char ch)
{
char *str = a;
while(*a)
{
a++;
}
while(a-- != str && *a != ch);
if(*a == ch)
return a;
return NULL;
}
int main(int argc, char argv[])
{
char *a = "www.baidu.com";
char ch = '.';
printf("%s\n",a);
printf("%s\n",my_strchr(a,ch));
}