[求助]输入两个字符串,把含有两个字符串的最小长度的字符串输出
/*输入两个字符串,把含有两个字符串的最小长度的字符串输出.如abc,cde,则输出abcde*//*为什么我的这个程序错了呢?*/
/*关于链表我刚在学习,这个程序谁能帮我看看啊,谢谢!*/
#include "stdio.h"
#include "conio.h"
struct link
{
char ch;
struct link *next;
};
struct link *head1,*head2,*pr1,*pr2,*p1,*p2;
main()
{
char c;
head1=(struct link *)malloc(sizeof(struct link));
pr1=head1;
pr2=head2;
printf("Please input the first string:");
while((c=getchar())!='\r')
{
pr1->ch=c;
p1=(struct link *)malloc(sizeof(struct link));
p1->next=NULL;
p1=pr1->next;
pr1=p1;
}
printf("\nPlease input the second string:");
while((c=getchar())!='\r')
{
pr2->ch=c;
p2=(struct link *)malloc(sizeof(struct link));
p2->next=NULL;
p2=pr2->next;
pr2=p2;
}
while(1)
{
while(pr1->ch!=head2->ch&&pr1!=NULL)
{
pr1=pr1->next;
p1=pr1;
}
if(pr1==NULL)
pr1=pr2;
else
T:{
pr1=pr1->next;
pr2=pr2->next;
if(pr2==NULL)
{
pr1=head1;
while(pr1!=NULL)
{
printf("%c",pr1->ch);
pr1=pr1->next;
}
getch();
exit(0);
}
if(pr1==NULL)
{
pr1=pr2->next;
pr1=head1;
while(pr1!=NULL)
{
printf("%c",pr1->ch);
pr1=pr1->next;
}
getch();
exit(0);
}
if(pr1!=NULL&&pr2!=NULL)
{
if (pr2->ch!=pr2->ch)
{
pr1=pr1->next;
continue;
}
else goto T;
}
}
}
getch();
}