| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 2095 人关注过本帖
标题:[求助]c程序的一个错误
只看楼主 加入收藏
andself
Rank: 1
等 级:新手上路
帖 子:60
专家分:0
注 册:2007-9-23
收藏
 问题点数:0 回复次数:38 
[求助]c程序的一个错误
(这个错误多啊! 我在后面又贴了我改了一半的 大家看后面的那个 谢谢)

红色的这里 出错了 帮我看看啊 就这一个错啊~~~~~~~~~~~``
大家帮忙啊~~~~~


menu()
{
printf(" ___________________________");
printf(" |(1)Creat a new linklist. |\n");
printf(" |(2)Locate. |\n");
printf(" |(3)Get element. |\n");
printf(" |(4)The length of linklist. |\n");
printf(" |(5)Inside an element. |\n");
printf(" |(6)Delete an element. |\n");
printf(" |(7)EXIT. |\n");
printf(" |___________________________|\n");
printf("Please input the number of your choose.\n");
}

int choose()
{
int a;
scanf("%d",&a);
return(a);
}

Node *CreatL()
{
LinkList L;
Node *r,*s;
int flag=1;
L=(Node *)malloc(sizeof(Node));
L->next=NULL;
r=L;
while(flag)
{
c=getcher();
if(c!='$')
{ s=(Node *)malloc(sizeof(Node));
s->next=c;
r->next=s;
r=s;
}
else
{ flag=0;
r->next=NULL;
}
}
return L;
}

Node *Locate(LinkList L)
{
Node *p;
int b=1;
char i;
scanf("%c",&i);
p=L->next;
while(p!=NULL)
if(p->date!=i)
{
p=p->next;
b++;
}
else break;
printf("This element's locate is %d",b);
}

Node *Get(LinkList L)
{
int j,i;
char a;
Node *p;
scanf("%d",&i);
p=L;
j=o;
while(p->next!=NULL&&j<i)
{
p=p->next;
j++;
}
if(i==j)
{
a=p->data;
printf("The i'th element is %c",a);
}
else printf("The i is wrong.\n");
}

int Listlength(LinkList L)
{
Node *p;
int j;
p=L->next;
j=0;
while(p!=NULL)
{
p=p->next;
j++;
}
printf("This Linklist's length is %d",j);
}

int InsList(LinkList L,int i,char e)
{
Node *pre,*s;
int k;
pre=L;
k=0;
while(pre!=NULL&&k<i-1)
{
pre=pre->next;
k=k+1;
}
if(k!=i-1)
{
printf("The i is wrong!\n");
return ERROR;
}
s=(Node *)malloc(sizeof(Node));
s->data=e;
s->next=pre->next;
pre->next=s;
return L;
}

int DelList(LinkList L,int i2,char e2)
{
Node *p,*r;
int k;
p=L;
k=o;
while(p->next!=NULL&&k<i2-1)
{
p=p->next;
k=k+1;
}
if(K!=i2-1)
{
printf("The position is wrong!\n");
return ERROR;
}
r=p->next;
p->next=p->next->next;
*e2=r->data;
free(r);
return OK;
}

main()
{
char c,e,e2;
LinkList L;
int i,i2,x=1,y,*p;
printf("Please creat a linklist.");
printf("Please input something and enter '$'to end.\n");
L=CreatL();
while(x)
{
menu();
y=choose;
if(y>0&&y<8)
{
if(a=1) { printf("please input something and enter '$' to end.\n");
L=CreatL();
}
else
if(a=2) { printf("Please enter the element which you find.\n");
Node *Locate(LinkList L);
}
else
if(a=3)
{ printf("Please enter the position of the element which you find.\n");
Node *Get(LinkList L);
}
else
if(a=4) Listlength(LinkList L);
else
if(a=5)
{
printf("Please input the element e and the locate i.\n");
printf("i="); scanf("%d",&i);
printf("\ne="); scanf("%c",&e);
printf("\n");
L=InsList(LinkList L, int i , char e);
printf("The new LinkList is:\n");
p=L->next;
while(p!=NULL)
{
printf("%c",p->data);
p=p->next;
}
}
else
if(a=6)
{
printf("Please input the element e and the locate i.\n");
printf("i2="); scanf("%d",&i2);
printf("\ne2="); scanf("%c",&e2);
printf("\n");
L=DelList(LinkList L, int i2 , char e2);
printf("The new LinkList is:\n");
p=L->next;
while(p!=NULL)
{
printf("%c",p->data);
p=p->next;
}
}
else if(a=7) return(1);
printf("(1)Go on (0)EXIT\n");
scanf("%d",&x);
}
else printf("ERROR");
}
}

[此贴子已经被作者于2007-9-29 8:28:01编辑过]

搜索更多相关主题的帖子: element c程序 
2007-09-28 19:15
nuciewth
Rank: 14Rank: 14Rank: 14Rank: 14
来 自:我爱龙龙
等 级:贵宾
威 望:104
帖 子:9786
专家分:208
注 册:2006-5-23
收藏
得分:0 

你的结构体呢.
c=getchar();

语法上没有问题.
你要不去看看我的链表帖子吧.


倚天照海花无数,流水高山心自知。
2007-09-28 22:52
andself
Rank: 1
等 级:新手上路
帖 子:60
专家分:0
注 册:2007-9-23
收藏
得分:0 
c=getchar(); 这个么?
有呢么

2007-09-28 22:57
andself
Rank: 1
等 级:新手上路
帖 子:60
专家分:0
注 册:2007-9-23
收藏
得分:0 

就是这个 不知道 怎么错了
Node *CreatL()
{
LinkList L;
Node *r,*s;
int flag=1;
L=(Node *)malloc(sizeof(Node));
L->next=NULL;
r=L;
while(flag)
{
c=getcher();
if(c!='$')
{ s=(Node *)malloc(sizeof(Node));
s->next=s;
r=s;
}
else
{ flag=0;
r->next=NULL;
}
}
return L;
}


2007-09-28 23:22
nuciewth
Rank: 14Rank: 14Rank: 14Rank: 14
来 自:我爱龙龙
等 级:贵宾
威 望:104
帖 子:9786
专家分:208
注 册:2006-5-23
收藏
得分:0 
结构体定义在哪?

倚天照海花无数,流水高山心自知。
2007-09-28 23:23
nuciewth
Rank: 14Rank: 14Rank: 14Rank: 14
来 自:我爱龙龙
等 级:贵宾
威 望:104
帖 子:9786
专家分:208
注 册:2006-5-23
收藏
得分:0 
s-&gt;next=s;

倚天照海花无数,流水高山心自知。
2007-09-28 23:25
andself
Rank: 1
等 级:新手上路
帖 子:60
专家分:0
注 册:2007-9-23
收藏
得分:0 
s-&gt;next=s;  这个错了么?

2007-09-28 23:27
nuciewth
Rank: 14Rank: 14Rank: 14Rank: 14
来 自:我爱龙龙
等 级:贵宾
威 望:104
帖 子:9786
专家分:208
注 册:2006-5-23
收藏
得分:0 
我写的.
node* Creat_Node()
{
node *head,*pre,*p;
int x;
head=(node*)malloc(sizeof(node));;
head->next=NULL;
pre=head;
printf("输入各结点的值,以0结束:");
while(EOF!=(scanf("%d",&x))&&x!=0)
{
p=(node*)malloc(sizeof(node));
p->info=x;
p->next=pre->next;
pre->next=p;
pre=pre->next;
}
return head;
}

倚天照海花无数,流水高山心自知。
2007-09-28 23:27
andself
Rank: 1
等 级:新手上路
帖 子:60
专家分:0
注 册:2007-9-23
收藏
得分:0 
编译的时候 显示错误在这里 Node *CreatL()

2007-09-28 23:27
nuciewth
Rank: 14Rank: 14Rank: 14Rank: 14
来 自:我爱龙龙
等 级:贵宾
威 望:104
帖 子:9786
专家分:208
注 册:2006-5-23
收藏
得分:0 
以下是引用andself在2007-9-28 23:27:06的发言:
s->next=s; 这个错了么?

自己的next指向自己.


倚天照海花无数,流水高山心自知。
2007-09-28 23:28
快速回复:[求助]c程序的一个错误
数据加载中...
 
   



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

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