标题:这个编程不知道为何不行,但是我在主函数void上面加一个花括号‘}’就可以了 ...
只看楼主
lxl1026
Rank: 1
等 级:新手上路
帖 子:4
专家分:0
注 册:2010-11-16
结帖率:0
已结贴  问题点数:20 回复次数:4 
这个编程不知道为何不行,但是我在主函数void上面加一个花括号‘}’就可以了 ,很奇怪,请各位帮我看看
#include<stdio.h>
#include<malloc.h>
#define NULL 0
#define LEN sizeof(struct student)


struct student
{long num;
float score;
struct student *next;
};

int n;
struct student *creat(void)
{struct student *head;
struct student *p1,*p2;
n=0;
p1=p2=(struct student *) malloc(LEN);
scanf("%ld,%f",&p1->num,&p1->score);
head=NULL;
while(p1->num!=0)
{n=n+1;
if(n==1)head=p1;
else p2->next=p1;
p2=p1;
p1=(struct student *)malloc(LEN);
scanf("%ld,%f",&p1->num,&p1->score);
}
p2->next=NULL;
return(head);
}


void print(struct student *head)
{struct student *p;
printf("\nNOW,these %d record are:\n",n);
p=head;
if(head!=NULL)
do
{printf("%ld %5.1f\n",p->num,p->score);
p=p->next;
}
while(p!=NULL);
}


struct student *del(struct student *head,long num)
{struct student *p1,*p2;
if(head==NULL)
{printf("\nlist null! \n");goto end;}
p1=head;
while(num!=p1->num&&p1->next!=NULL)
{p2=p1;p1=p1->next;}
if(num==p1->num)
{if(p1==head) head=p1->next;
else p2->next=p1->next;
printf("delete:%ld\n",num);
n=n-1;}
else printf("%ld not been found!\n",num);
end:
return(head);
}

struct student  *insert(struct student *head,struct student *stud)
{struct student *p0,*p1,*p2;
p1=head;
p0=stud;
if(head==NULL)
{head=p0;p0->next=NULL;
}
else
{while((p0->num>p1->num)&&(p1->next!=NULL))
{p2=p1;
p1=p1->next;}
if(p0->num<=p1->num)
{if(head==p1)head=p0;
else p2->next=p0;
p0->next=p1;
}
else
{p1->next=p0;p0->next=NULL;
}
n=n+1;
return(head);

}          假如在这里加多一个花括号,就可以了,很费解

void main()
{
struct student *head,*stu;
long del_num;
printf("input records:\n");
head=creat();
print(head);
printf("\ninput the deleted number:");
scanf("%ld",&del_num);
while(del_num!=0)
{head=del(head,del_num);
print(head);
printf("\ninput the deleted number:");
scanf("%ld",&del_num);
}
printf("\ninput the insert record:");
stu=(struct student *)malloc(LEN);
scanf("%ld,%f",&stu->num,&stu->score);
while(stu->num!=0)
{head=insert(head,stu);
print(head);
printf("input the inserted record:");
stu=(struct student *)malloc(LEN);
scanf("%ld,%f",&stu->num,&stu->score);
}
}









































搜索更多相关主题的帖子: void 括号 函数 
2010-11-16 18:21
lansong
Rank: 4
等 级:业余侠客
帖 子:79
专家分:226
注 册:2009-6-11
得分:5 
这程序是你写的吗?表示怀疑。

2010-11-16 23:58
vandychan
Rank: 15Rank: 15Rank: 15Rank: 15Rank: 15
等 级:贵宾
威 望:18
帖 子:2296
专家分:6418
注 册:2010-8-20
得分:5 
应该是自己写+网上下载

到底是“出来混迟早要还”还是“杀人放火金腰带”?
2010-11-17 01:15
韭菜
Rank: 2
等 级:论坛游民
帖 子:51
专家分:94
注 册:2010-9-26
得分:5 
程序代码:
struct student  *insert(struct student *head,struct student *stud)
{
    struct student *p0,*p1,*p2;
    p1=head;
    p0=stud;
    if(head==NULL)
    {
        head=p0;
        p0->next=NULL;
    }
    else
    {
        while((p0->num>p1->num)&&(p1->next!=NULL))
        {
            p2=p1;
            p1=p1->next;
        }
        if(p0->num<=p1->num)
        {
            if(head==p1)    head=p0;
            else p2->next=p0;
            p0->next=p1;
        }
        else
        {
            p1->next=p0;
            p0->next=NULL;
        }
        n=n+1;
    return(head);

}}        // 假如在这里加多一个花括号,就可以了,很费解----这里需要两个括号:一个是与else处的括号相对应
                //一个是该函数的括号。 写代码的时候,注意下格式,你会看的很有结构条理。
2010-11-17 08:48
自由战士89
Rank: 5Rank: 5
等 级:职业侠客
帖 子:154
专家分:387
注 册:2010-9-2
得分:5 
这代码格式受不了,那多个 } 就对吗?返回值呢?
2010-11-17 09:56



参与讨论请移步原网站贴子:https://bbs.bccn.net/thread-325955-1-1.html




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

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