#include <stdio.h>
#include <stdlib.h>
#define LIM 20
char *function2( char g ,char *s)
{ int i=0;
char *p=0;
while(s[i]!='\0')
{ if(s[i]==g)
{ p=&s[i];
break;
}
i++;
}
return p;
}
void function1()
{ int i;
char s[LIM];
char g;
char *p;
while((scanf("%c",&s[i])==1)&&(s[i]!='\n'))
{
i++;
if(i>=LIM)
break;
}
s[i]='\0';
printf("输入要检索的字符:");
scanf("%c",&g);
printf("\n");
p=function2(g,s);
if(p!=NULL)
printf("指向第一个字符的指针p:%p",p);
else
printf("无该字符,指针%p",p);
}
int main()
{
function1();
system("pause");
return 0;
}
19行int i=0;
第19行,修改为:int i=0; 这里 i 没有初始化。