1 // mystrchr.cpp : Defines the entry point for the console application.
2 //
3
4 #include "stdafx.h"
5 #include "stdio.h"
6 #include "stdlib.h"
7 #include "string.h"
8
9
10
11 char *MyStrChr(char *pstr,char ch)
12 {
13
14 if (pstr==NULL)
15 {
16 return NULL;
17 }
18 else
19 {
20 while(*pstr!='\0')
21 {
22 if(*pstr==ch)
23 {
24 return pstr;
25 }
26 pstr++;
27
28 }
29
30 }
31 return NULL;
32 }
33
34
35
36
37
38 int main(int argc, char* argv[])
39 {
40 char str1[20]="mynameisxxxxxxxxxxxxxxxx";
41 char ch='f';
42 char *pstr1=MyStrChr(str1,ch);
43 if (pstr1==NULL)
44 {
45 printf("没有找到\n");
46
47 }
48 else
49 {
50 printf("ch=%c,str1=%s\n,dizhi=%x\n",*pstr1,pstr1,pstr1);
51 }
52
53
54
55 system("pause");
56 return 0;
57 }