| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 748 人关注过本帖
标题:请帮忙看看我这个程序的错误的问题
只看楼主 加入收藏
蚂蚁的哲学
Rank: 2
来 自:湖北
等 级:论坛游民
帖 子:25
专家分:24
注 册:2010-8-22
结帖率:100%
收藏
已结贴  问题点数:20 回复次数:10 
请帮忙看看我这个程序的错误的问题
#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 records are:\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");
    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)
        {
            p1=p2;
            p1=p1->next;
        }
        if(p0->num<=p1->num)
        {
            if(p1==head)
                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 stu,*head;
        long del_num;
        printf("Input records:\n");
        head=creat();
        print(head);
        printf("\nInput the deleted number:");
        scanf("%ld",&del_num);
        head=del(head,del_num);
        print(head);
        printf("\nInput the inserted record:");
        scanf("%ld,%f",&stu.num,&stu.score);
        head=insert(head,&stu);
        print(head);
    }





--------------------Configuration: List - Win32 Debug--------------------
Compiling...
List.c
D:\Program Files\Microsoft Visual Studio\MyProjects\all\List.c(114) : error C2143: syntax error : missing ';' before 'type'
D:\Program Files\Microsoft Visual Studio\MyProjects\all\List.c(117) : error C2143: syntax error : missing ';' before 'type'
D:\Program Files\Microsoft Visual Studio\MyProjects\all\List.c(122) : error C2065: 'del_num' : undeclared identifier
D:\Program Files\Microsoft Visual Studio\MyProjects\all\List.c(126) : error C2065: 'stu' : undeclared identifier
D:\Program Files\Microsoft Visual Studio\MyProjects\all\List.c(126) : error C2224: left of '.num' must have struct/union type
D:\Program Files\Microsoft Visual Studio\MyProjects\all\List.c(126) : error C2224: left of '.score' must have struct/union type
D:\Program Files\Microsoft Visual Studio\MyProjects\all\List.c(127) : warning C4133: 'function' : incompatible types - from 'int *' to 'struct student *'
执行 cl.exe 时出错.

List.exe - 1 error(s), 0 warning(s)



请帮我指出,谢谢!
搜索更多相关主题的帖子: head next include 
2010-10-02 21:38
蚂蚁的哲学
Rank: 2
来 自:湖北
等 级:论坛游民
帖 子:25
专家分:24
注 册:2010-8-22
收藏
得分:0 
为什么说我程序中的del_num,stu未定义,
.num和.score左侧类型不是结构体,
以及warning中的类型不一致的问题,先谢谢各位了!

Hello!
2010-10-02 21:41
遮天云
Rank: 11Rank: 11Rank: 11Rank: 11
来 自:农村一小伙
等 级:贵宾
威 望:12
帖 子:1132
专家分:2671
注 册:2010-6-1
收藏
得分:20 
程序代码:
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)
        {
            p1=p2;
            p1=p1->next;
        }
        if(p0->num<=p1->num)
        {
            if(p1==head)
                head=p0;
            else
                p2->next=p0;
            p0->next=p1;
        }
        else
        {
            p1->next=p0;
            p0->next=NULL;
        }
        n=n+1;
        return(head);
    }

}//加上这个大括号
这样就没错了
2010-10-02 21:43
vandychan
Rank: 15Rank: 15Rank: 15Rank: 15Rank: 15
等 级:贵宾
威 望:18
帖 子:2296
专家分:6418
注 册:2010-8-20
收藏
得分:0 
遮天大哥老是这么热心

到底是“出来混迟早要还”还是“杀人放火金腰带”?
2010-10-02 21:47
蚂蚁的哲学
Rank: 2
来 自:湖北
等 级:论坛游民
帖 子:25
专家分:24
注 册:2010-8-22
收藏
得分:0 
Oh my god!
超级失误啊
大括号都忘了,怎粗心 ,非常感谢哈!

Hello!
2010-10-02 21:48
遮天云
Rank: 11Rank: 11Rank: 11Rank: 11
来 自:农村一小伙
等 级:贵宾
威 望:12
帖 子:1132
专家分:2671
注 册:2010-6-1
收藏
得分:0 
以下是引用蚂蚁的哲学在2010-10-2 21:48:19的发言:

Oh my god!
超级失误啊
大括号都忘了,怎粗心 ,非常感谢哈!
下次注意就行了!呵呵
2010-10-02 21:49
蚂蚁的哲学
Rank: 2
来 自:湖北
等 级:论坛游民
帖 子:25
专家分:24
注 册:2010-8-22
收藏
得分:0 
Ths
下次一定注意哈!

Hello!
2010-10-02 21:58
蚂蚁的哲学
Rank: 2
来 自:湖北
等 级:论坛游民
帖 子:25
专家分:24
注 册:2010-8-22
收藏
得分:0 
这个程序我运行的时候,经常出现无法输入第2个record的现象,
我是个新手,可以指点下吗?

Hello!
2010-10-02 22:00
遮天云
Rank: 11Rank: 11Rank: 11Rank: 11
来 自:农村一小伙
等 级:贵宾
威 望:12
帖 子:1132
专家分:2671
注 册:2010-6-1
收藏
得分:0 
我看看哈!看能不能解决
2010-10-02 22:07
蚂蚁的哲学
Rank: 2
来 自:湖北
等 级:论坛游民
帖 子:25
专家分:24
注 册:2010-8-22
收藏
得分:0 
  你把94行改成  p2=p1
之前是反了
嘿嘿  
刚开始学,没遇见过这样的现象哈

Hello!
2010-10-02 22:09
快速回复:请帮忙看看我这个程序的错误的问题
数据加载中...
 
   



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

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