strchr()函数
:
功能就是找出在字符串str中第一次出项字符ch的位置,找到就返回该字符位置的指针(也就是返回该字符在字符串中的地址的位置),找不到就返回空指针
针(就是 null)。
功能就是找出在字符串str中第一次出项字符ch的位置,找到就返回该字符位置的指针(也就是返回该字符在字符串中的地址的位置),找不到就返回空指针
#include<stdio.h>
#include<string.h>
int buildTree(int n,char *a,char *b,char *c)
{
char *p=b;
int t;
if(n<=0) return 0;
/*while(1)
{
if(*a==*p) break;
else p++;
}*/
p=strchr(b,*a);//strchr函数
t=p-b;
buildTree(t,a+1,b,c);//a不能忘加1!!!
buildTree(n-1-t,a+t+1,b+t+1,c+t);
c[n-1]=*a;
}
int main()
{
char a[30],b[30],c[30];
int n,i;
while(scanf("%s%s",a,b)!=EOF)
{
n=strlen(a);
buildTree(n,a,b,c);
c[n]='\0';
printf("%s\n",c);
}
return 0;
}
针(就是 null)。