编写一个函数,函数首部为void maxword(char *s,char *t),求出两个字符串包含的相同单词(同一字母的大小写视为不同的字符)。规定单词全部由英文字母构成,单词直接由一个或多个空格分隔。其中主函数如下:
#include
Void main()
{
Char s[]=”This is C programming text”;
Char t[]=”This is a text for C programming”;
maxword(s,t);
}
====我自己编写了一个如下程序,但是不知道为何程序运行失败
#include
#include
void maxword(char *s,char *t)
{
int i,j=0,k=0,m=0,n=0;
char *p[81],*q[81];
for(i=0;s[i]!=0;i++)
{
if(s[i]!=' ')
{
p[m][j++]=s[i];
}
else
{
p[m][j]=0;
m++;
j=0;
}
}
for(i=0;t[i]!=0;i++)
{
if(t[i]!=' ')
{
q[n][k++]=t[i];
}
else
{
q[n][k]=0;
n++;
k=0;
}
}
for(i=0;i<m;i++)
{
for(j=0;j<n;j++)
{
if(strstr(p[i],q[j])!=NULL)
{
printf("the same word:%s\n",p[i]);
}
}
}
}
void main()
{
char s[]="This is C programming text";
char t[]="This is a text for C programming";
maxword(s,t);
}