| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 1067 人关注过本帖
标题:请教:unhandled exception in**exe出错了,不知道该怎么改?
只看楼主 加入收藏
wxhpy
Rank: 1
来 自:南昌
等 级:新手上路
帖 子:3
专家分:0
注 册:2009-9-17
结帖率:100%
收藏
已结贴  问题点数:10 回复次数:1 
请教:unhandled exception in**exe出错了,不知道该怎么改?
由于刚申请的号,分不多,麻烦各位高手指教啊:在书上看到了这样一个程序,在运行时输入相应的数字后,出现了unhandled exception in**exe字样,由于刚开始学数据结构,以及C语言,麻烦高手指教,该怎么改,错在哪里。
这个程序目的是:让计算机随机产生10个数并存到线性链表中,
遍历线性链表并输出各节点值,对所产生的线性链表进行逆置。
程序如下所示:



#include "stdio.h"
#include "malloc.h"
#include "stdlib.h"
#define LEN sizeof(struct node)
#define num 10
typedef int elemtype;
struct node
{
    elemtype data;//数据域
    struct node *next;
};
struct node* InitList()//链表初始化函数
{
    struct node* head=(struct node *)malloc(LEN);
    if (head==NULL)
    {
        printf("Memory allocation failure!\n");
        exit(1);//有1表示出错返回
    }
    head->next=NULL;
    return head;
}
int Insert(struct node* head,int i,elemtype x)//元素X插入到i位置
{
    struct node*p=head;
    struct node* newp;//用newp来指向新申请的节点
    int cout=0;//计数来用
    if (i<1)
    {
        printf("Error!The wrong argument!");
        return 0;
    }
    while ((p!=NULL)&&(cout<i-1))
    {
        p=p->next;//让P指向下一个节点
        cout++;
    }//让P找到指定的节点
    if (p=NULL)
    {
        printf("链表长度小于%d\n",i-1);
        return 0;
    }
 newp=(struct node*)malloc(LEN);//申请时要进行判断
 if (newp==NULL)
 {
     printf("Memory allocation failure!\n");
     return 0;//0值在这里表示插入不成功

 }
 newp->data=x;
 newp->next=p->next;
 p->next=newp;
 return 1;

}
void Traverse(struct node* head)//线性链表遍历函数
{
    struct node*p=head->next;//跳过附加表头节点
    while (p!=NULL)
    {
        printf("   %d",p->data);
        p=p->next;
    }

}
void create(struct node *head)
{
    int i,j;
    for(i=1;i<=num;i++)
    {
        j=rand();//产生随机数
        Insert(head,i,j);//将一个随机数插入到链表中

    }
}
void reverse(struct node*head)
{
    struct node*cp=head->next;
    struct node*pp=NULL;//指向当前节点的前驱
    struct node*np;//指向当前节点的后继
    while (cp!=NULL)
    {
        np=cp->next;cp->next=pp;
        pp=cp;
        cp=np;
    }
    head->next=pp;


}
void main()
{
    int i=1;
    struct node*h;
    h=InitList();
    while(i!=0)
    {
        scanf("%d",&i);
        switch (i)
        {
        case 0:exit(0);
        case 1:create(h);
            break;
        case 2:reverse(h);
            break;
        case 3:Traverse(h);
            break;
        default :  
            printf("输入错误,重新输入");
        
        }
    }
}
搜索更多相关主题的帖子: unhandled exe exception 
2009-09-17 00:59
chenaiyuxue
Rank: 5Rank: 5
来 自:山东滨州
等 级:职业侠客
帖 子:334
专家分:370
注 册:2008-5-20
收藏
得分:10 
回复 楼主 wxhpy
Insert函数中if (p = NULL)中少写了一个等号,改成if (p == NULL)

你是雪,我是尘埃,相遇是意外;你坠落,在我胸怀,流进我血脉。
2009-09-17 10:23
快速回复:请教:unhandled exception in**exe出错了,不知道该怎么改?
数据加载中...
 
   



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

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