| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 509 人关注过本帖
标题:[求助]单链表储存数据的问题
只看楼主 加入收藏
zero0c
Rank: 1
等 级:新手上路
帖 子:15
专家分:0
注 册:2007-10-12
收藏
 问题点数:0 回复次数:2 
[求助]单链表储存数据的问题
自学C,今天在书上看到有关单链表的内容,联系了一下在本论坛上关于模拟密码输入的帖子,决定写个无限制密码位数的程序(如下),什么地方搞错了?
#include <conio.h>
#include <stdlib.h>
#include <stdio.h>
struct psw
{
char c;
struct psw * next;
};
struct psw * add(struct psw * head,char c)
{
struct psw * p1;
//如果head的指针域为空,则申请一个节点,存入一个字符,并它赋予head的指针域;同时......
while(head->next=NULL)
{
p1=(struct psw *) malloc(sizeof(struct psw));
p1->next=NULL;
p1->c=c;
head->next=p1;
}
return head;
}
void show(struct psw * head)
{
struct psw * temp;
temp=head;
printf("\n");
while((temp->next)!=NULL)
{
printf("Right now you input:%c",(temp->next)->c);
temp=temp->next;
}
getch();
}
int main()
{
char c;
struct psw * head;
struct psw p;
head=&p;
p->next=NULL;
p->c='\0';
do
{
c=getch();
printf("*");
p=add(p,c);
}while(c!=13);
show(head);
}

[此贴子已经被作者于2007-10-20 20:31:38编辑过]

搜索更多相关主题的帖子: 单链 数据 储存 
2007-10-20 20:21
windlzf
Rank: 1
等 级:新手上路
帖 子:56
专家分:0
注 册:2006-8-7
收藏
得分:0 
#include <conio.h>
#include <stdlib.h>
#include <stdio.h>
struct psw
{
char c;
struct psw *next;
};
struct psw *add(struct psw *head,char c)
{
struct psw *p1;
if(head->next==NULL)
{
p1=(struct psw *)malloc(sizeof(struct psw));
p1->next=NULL;
p1->c=c;
head->next=p1;
head=p1;
}
return head;
}
void show(struct psw *head)
{
struct psw *temp;
temp=head;
printf("\nRight now you input:");
while((temp->next)!=NULL)
{
printf("%c",(temp->next)->c);
temp=temp->next;
}
getch();
}
int main()
{
char c;
struct psw *head;
struct psw *p;
p=(struct psw *)malloc(sizeof(struct psw));
if(p==NULL) return -1;
p->next=NULL;
p->c='\0';
head=p;
do
{
c=getch();
printf("*");
p=add(p,c);
}while(c!=13);
show(head);
return 0;
}
2007-10-22 11:32
ondy
Rank: 1
等 级:新手上路
威 望:1
帖 子:88
专家分:0
注 册:2007-9-4
收藏
得分:0 
编译器报什么错

2007-10-22 15:12
快速回复:[求助]单链表储存数据的问题
数据加载中...
 
   



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

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