#include <stdio.h>
#include <stdlib.h>
struct Node_{
char c;
struct Node_*next;
};
struct Node_ *Creatnode()
{
int n=0;
struct Node_*phead,*prear,*newnode;
newnode=(struct Node_*)malloc(sizeof(struct Node_));
phead=NULL;
while (newnode->c!='p') {
if(n==0)
phead=newnode;
else
prear->next=newnode;
prear=newnode;
print("please input a char:\n");
scanf("%c",&newnode->c);
n++;
prear->next=NULL;
return phead;
}
}
struct Node_*Findnode(struct Node_ *head,int dates)
{
struct Node_*p;
p=head;
while (p->c!=dates&&p->next!=NULL) {
p=p->next;
if(p->c==dates)
return p;
else
return NULL;
}
}
struct Node_*FindAhead(struct Node_*head,int dates)
{
struct Node_ *p,*q;
q=NULL;
p=head;
while (p->c!=dates&&p->next!=NULL) {
p=p->next;
if(p->c==dates)
return p;
else
return NULL;
}
}
struct Node_*Deletenode(struct Node_ *head,int dates)
{
struct Node_ *delete,*p;
p=FindAhead(head, dates);
p=Findnode(head, dates);
if(!delete)
return NULL;
else
p->next=delete->next;
free(delete);
return head;
}
void display(struct Node_ *head)
{
struct Node_ *p;
p=head;
if(p!=NULL){
printf(" %c\n",p->c);
p=p->next;
}
}
int main()
{
struct Node_ *head,*fd;
head=Creatnode();
display(head);
fd=FindAhead(head,'q');
if(fd==NULL)
printf("Ahead of found is null\n");
else
printf("%c\n",fd->c);
printf("Hello, World!\n");
return 0;
}
题目要求用户一个一个输入字符,当输入q时,打印出之前所有输入的并结束程序,并注意内存泄露问题。为什么有错啊,编译器提示有错,但是代码没错