怎么改变输入方式呢?我想要的输入方式“beautiful aut”,现在的输入方式是“beautiful(回车键)aut(回车键)”,
目的是输出“betuaiful”,实现子串逆置
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
typedef char elementype;
typedef struct node
{
elementype data;
struct node *next;
} linkstr;
linkstr *invertsubstring(linkstr *s, linkstr *t)
{
linkstr *begin, *p, *t1, *r, *q, *u, *pr;
pr = s;
p = s;
t1 = t;
while (p != NULL && t1 != NULL)
{
if (p->data == t1->data)
{
p = p->next;
t1 = t1->next;
}
else
{
begin = pr;
pr = pr->next;
p = pr;
t1 = t;
}
}
if (t1 != NULL)
{
printf("主串中没有匹配的子串\n");
return s;
}
else
{
q = begin->next;
r = q->next;
q->next = p;
while (r != p)
{
u = r->next;
r->next = q;
q = r;
r = u;
}
begin->next = q;
}
return s;
}
linkstr *crtlinked()
{
linkstr *s, *p, *head;
char ch;
head = NULL;
p = head;
scanf("%c", &ch);
while (ch != '\n')
{
s = (linkstr *) malloc(sizeof(linkstr));
s->data = ch;
if (head == NULL)
head = s;
else p->next = s;
p = s;
scanf("%c", &ch);
}
p->next = NULL;
return head;
}
void print_link(linkstr *s)
{
linkstr *v;
v = s;
while (v)
{
if(v->next)
printf("%c", v->data);
else
printf("%c", v->data);
v = v->next;
}
}
void main()
{
linkstr *s, *t, *m;
s = (linkstr *) malloc(sizeof(linkstr));
t = (linkstr *) malloc(sizeof(linkstr));
printf("请输入字符串:\n");
s = crtlinked();
printf("请输入要逆置的字符串:\n");
t = crtlinked();
m = (linkstr *) malloc(sizeof(linkstr));
m = invertsubstring(s, t);
print_link(m);
}