#include <malloc.h>
#include <stdio.h>
struct node
{
char ch;
struct node *next;
}
main()
{
void delete(struct node *p,char de);
char de;
int n=sizeof(struct node);
struct node *head,*ph;
printf("please input string end with \'!\':\n");
head=(struct node *)malloc(n); /*开辟头节点*/
ph=(struct node *)malloc(n);
head->next=ph;
while((ph->ch=getchar())!='!')
{ ph->next=(struct node *)malloc(n);
}
ph->next=Null;
printf("please input the letter you want to detele:");
scanf("%c",&de); /*输入要删除的字符*/
delete(head->next,de);
printf("\nthe changed string :%s\n",head->next);
getch();
}
void delete(struct node * p,char de)
{struct node * p1=p;
for(;p->ch;)
{if(p->ch==de)
{
p1=p->next;
free(p);
p1=p;
continue;
}
p=p->next;
}
free(p);
free(p1);
}
麻烦大家帮我看看错在哪里了,为什么输入后得不到正确结果。
当输入字符窜结束后还没有等我输入要删除的字符程序运行就结束了。