| 编程中国 | 业界新闻 | 技术文章 | 视频教程 | 下载频道 | 程序源码 | 个人空间 | 编程论坛
全能ASP/PHP/ASP.NET主机,支持月付专业 MSSQL 数据库空间,支持月付专业 MySQL 数据库空间,支持月付学习型 ASP/PHP/ASP.NET 主机 30元/年
高端软件开发 = 年薪十万不是梦   
共有 199 人关注过本帖
标题:小菜~~~~~~求助!!
收藏  订阅  推荐  打印
甲鱼
Rank: 1
等级:新手上路
帖子:9
积分:136
注册:2008-10-4
小菜~~~~~~求助!!

各位高手能不能帮我看一下这个程序错在哪了?

#include <stdio.h>
#include <malloc.h>
#define NULL 0
#define LEN sizeof(struct list)
struct list
{
    int num;
    struct list *next;
};
int m,n;
struct list *creat1(void)
{
struct list *head,*p1,*p2;
    n=0;
    p1=p2=(struct list *)malloc(LEN);
    printf("please input the data1:");
    scanf("%ld",&p1->num);
    head=NULL;
    while(p1->num!=0)
    {
        n++;
        if(n==1) head=p1;
        else p2->next=p1;
        p2=p1;
        p1=(struct list *) malloc(LEN);
        scanf("%ld",&p1->num);
    }
    p2->next=NULL;
return(head);
}

struct list *creat2(void)
{
struct list *head,*p1,*p2;
m=0;
p1=p2=(struct list *)malloc(LEN);
    printf("please input the data1:");
    scanf("%ld",&p1->num);
    head=NULL;
    while(p1->num!=0)
    {
        m++;
        if(n==1) head=p1;
        else p2->next=p1;
        p2=p1;
        p1=(struct list *) malloc(LEN);
        scanf("%ld",&p1->num);
    }
    p2->next=NULL;
return(head);
}

void print(struct list *head)
{struct list *p;
p=head;
    do
    {
        printf("%ld",p->num);
        p=p->next;
    }while(p->next!=NULL);  
    printf("%3d",p->num);
    getchar();
}


struct list *toghter(struct list *head1,struct list *head2)
{
struct list *p1,*p2,*p3,*p4,*head;
    p1=head1;
    p2=head2;
    head=head1;
    while(p1->next!=NULL&&p2->next!=NULL)
    {
        p3=p1->next;
        p4=p2->next;
        p1->next=p2;
        p2->next=p3;
        p1=p3;
        p2=p4;
    }
    if(p1->next==NULL&&p2->next==NULL)
        p1->next=p2;
    if(p1->next==NULL&&p2->next!=NULL)
        p1->next=p2;
    if(p2->next==NULL&&p1->next!=NULL)
    {
        p3=p1->next;p1->next=p2;p2->next=p3;
    }
return(head);
}

void chain(struct list *head)
{struct list *tmp,*btmp;
int i,min;
for(i=0;i<n+m-1;i++)
{
  tmp=head;
  min=tmp->num;
  btmp=NULL;
  while(tmp->next)
{
if(min>tmp->next->num)
{
min=tmp->next->num;
btmp=tmp;
}
tmp=tmp->next;
}
printf("%d ",min);
}
}

void main()
{
struct list *head1,*head2,*head;
head1=creat1();
head2=creat2();
print(head1);
print(head2);
head=toghter(head1,head2);
chain(head);
}
2008-10-4 15:49
守鹤
Rank: 12Rank: 12Rank: 12
等级:版主
帖子:312
积分:3472
威望:11
来自:山東臨沂
注册:2008-6-20

1、   #define NULL 0这个语句删掉,系统已经定义了NULL
2、   把void main()改成 main()

知者知也,不知者不知也!
携手走夕阳待何时?
2008-10-4 16:47
blueboy82006
Rank: 12Rank: 12Rank: 12
等级:版主
帖子:1212
积分:12084
威望:16
来自:幻想世界
注册:2007-7-23

引用:
守鹤 在 2008-10-4 16:47 的发言:
2、   把void main()改成 main()
这是什么标准?

闭关修炼中!......
2008-10-4 17:33
守鹤
Rank: 12Rank: 12Rank: 12
等级:版主
帖子:312
积分:3472
威望:11
来自:山東臨沂
注册:2008-6-20

要看什么样的编译器了

如果在VC++中,当然void main()是正确的了

知者知也,不知者不知也!
携手走夕阳待何时?
2008-10-4 17:42
xiaoming8877
Rank: 1
等级:新手上路
帖子:29
积分:392
注册:2008-10-4

看不懂哦!!!!!

[b]10年的雨水熬成大树,10年的努力创造大成 [/b]
2008-10-5 13:31
共有 198 人关注过本帖
关于我们 | 广告合作 | 编程中国 | 清除Cookies | Archiver | WAP | TOP

编程中国 版权所有,并保留所有权利。鲁ICP备08000592号
Powered by Discuz, Processed in 0.051311 second(s), 9 queries.
Copyright©2004-2008, BCCN.NET, All Rights Reserved