这个好了
#include<stdio.h>
#include<string.h>
#include<malloc.h>
typedef struct Str
{
char s[50];
int num;
struct Str *next;
}Str;
void main()
{
Str *Stten(char *a,char *b),*c;
char a[500],b[500];
printf("Please input the firstline number:\n");
gets(a);
printf("Please input the secondline number:\n");
gets(b);
c=Stten(a,b);
while(c)
{
printf("%s ",c->s);
c=c->next;
}
}
Str *Stten(char *a,char *b)
{
int i=0,j=0,k=0,l=0;
Str *p1=NULL,*head=NULL;
Str *p3=NULL;
char *sp1,*sp2;
if(strlen(a)>strlen(b))
{
sp1=b,sp2=a;
}
else
{
sp1=a,sp2=b;
}
while(*(sp1+k)!='\0')
{
while(*(sp2+i)!='\0' && *(sp1+j)!='\0')
{
if(*(sp1+j)==*(sp2+i))
{
p1=(Str *)malloc(sizeof(Str));
p1->next=NULL;
while(*(sp1+j)==*(sp2+i) && *(sp2+i)!='\0' && *(sp1+j)!='\0')
{
*(p1->s+l)=*(sp2+i);
i++;
j++;
l++;
}
p1->num=l;
*(p1->s+l)='\0';
j=k;
l=0;
if(head==NULL)head=p1;
else if(head->num==p1->num)
{
p3=head;
while(p3->next)p3=p3->next;
p3->next=p1;
p3=NULL;
}
else if(head->num<p1->num)
head=p1;
}
else i++;
}
k++;
j=k;
i=0;
}
return head;
}