| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 509 人关注过本帖
标题:[求助]关于链表的问题
取消只看楼主 加入收藏
等待
Rank: 1
等 级:新手上路
帖 子:173
专家分:0
注 册:2005-12-1
结帖率:100%
收藏
 问题点数:0 回复次数:1 
[求助]关于链表的问题
/*函数作用:用带头节点的链表存储输入的字符窜并以‘!’结束,然后输入要删除的字符并输出该窜。*/
#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);
}
麻烦大家帮我看看错在哪里了,为什么输入后得不到正确结果。
当输入字符窜结束后还没有等我输入要删除的字符程序运行就结束了
2006-03-21 18:27
等待
Rank: 1
等 级:新手上路
帖 子:173
专家分:0
注 册:2005-12-1
收藏
得分:0 

真是谢谢各位的帮助,这问题捆扰了我好长时间现在终于解决了!


2006-03-24 13:17
快速回复:[求助]关于链表的问题
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.011738 second(s), 8 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved