| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 517 人关注过本帖
标题:程序可以编译通过,但是运行exe文件的时候,却出现错误而终止
只看楼主 加入收藏
legend2003cn
Rank: 1
等 级:新手上路
帖 子:6
专家分:0
注 册:2007-8-10
收藏
 问题点数:0 回复次数:2 
程序可以编译通过,但是运行exe文件的时候,却出现错误而终止

#include "stdlib.h"
#include "stddef.h"
#include "string.h"
#include "ctype.h"
#include "stdio.h"
#include "math.h"
#include "assert.h"

struct ArcBox
{
int tail, head;
struct ArcBox *hlink , *tlink;
}ArcBox;
struct FeaNode
{
char feaname[30];
int type;
union range
{
char *c_range[70];
int i_range[70];
double d_range[70];
}range;
int indegree;
int rangenum;
struct ArcBox *parent , *child;
}FeaNode;

struct BayesNetwork
{
struct FeaNode *fealist;
int feanum, arcnum;
}BayesNetwork;

struct FeaNode fealist[5]=
{{"land",0,{"0","1"},0,2,NULL,NULL},
{"wrong_fragment",1,{0},0,2,NULL,NULL},
{"urgent",1,{0},0,2,NULL,NULL},
{"hot",1,{0},0,2,NULL,NULL},
{"num_failed_logins",1,{0},0,2,NULL,NULL}};

void InitNB(struct BayesNetwork *nb)
{
fealist[1].range.i_range[0]=0;
fealist[1].range.i_range[1]=1;
fealist[2].range.i_range[0]=0;
fealist[2].range.i_range[1]=1;
fealist[3].range.i_range[0]=0;
fealist[3].range.i_range[1]=1;
fealist[4].range.i_range[0]=0;
fealist[4].range.i_range[1]=1;

nb->fealist=fealist;
nb->feanum=5;
nb->arcnum=0;

}

void TestInitNB(struct BayesNetwork *nb)
{
struct FeaNode *p;
InitNB(nb);
p=nb->fealist;
while(p)
{
printf("%s\t%d\t%d\t%d\n",p->feaname,p->type,p->indegree,p->rangenum);
p++;
}
printf("feature number = %d\n",nb->feanum);
printf("arc number = %d\n",nb->arcnum);
}


void main()
{
struct BayesNetwork *nb=NULL;
TestInitNB(nb);
}

问题可能处在nb的初始化的分配空间上,但是具体哪里有问题呢?请教大家,我真是头疼死了,多谢了!

搜索更多相关主题的帖子: 运行 编译 文件 exe 
2007-08-10 08:01
young
Rank: 3Rank: 3
等 级:论坛游侠
威 望:2
帖 子:223
专家分:160
注 册:2004-9-5
收藏
得分:0 

#include "stdlib.h"
#include "stddef.h"
#include "string.h"
#include "ctype.h"
#include "stdio.h"
#include "math.h"
#include "assert.h"

struct ArcBox
{
int tail, head;
struct ArcBox *hlink , *tlink;
}ArcBox;
struct FeaNode
{
char feaname[30];
int type;
union range
{
char *c_range[70];
int i_range[70];
double d_range[70];
}range;
int indegree;
int rangenum;
struct ArcBox *parent , *child;
}FeaNode;

struct BayesNetwork
{
struct FeaNode *fealist;
int feanum, arcnum;
}BayesNetwork;

struct FeaNode fealist[5]=
{{"land",0,{"0","1"},0,2,NULL,NULL},
{"wrong_fragment",1,{0},0,2,NULL,NULL},
{"urgent",1,{0},0,2,NULL,NULL},
{"hot",1,{0},0,2,NULL,NULL},
{"num_failed_logins",1,{0},0,2,NULL,NULL}};

void InitNB(struct BayesNetwork *nb)
{
fealist[1].range.i_range[0]=0;
fealist[1].range.i_range[1]=1;
fealist[2].range.i_range[0]=0;
fealist[2].range.i_range[1]=1;
fealist[3].range.i_range[0]=0;
fealist[3].range.i_range[1]=1;
fealist[4].range.i_range[0]=0;
fealist[4].range.i_range[1]=1;

nb->fealist=fealist;
nb->feanum=5;
nb->arcnum=0;

}

void TestInitNB(struct BayesNetwork *nb)
{
int i;
struct FeaNode *p;
InitNB(nb);
p=nb->fealist;
//while(p) // 陷入死循环
for(i=0; i < nb->feanum; i++)
{
printf("%s\t%d\t%d\t%d\n",p->feaname,p->type,p->indegree,p->rangenum);
p++;
}
printf("feature number = %d\n",nb->feanum);
printf("arc number = %d\n",nb->arcnum);
}

//#define __MY_TEST__

void main()
{
#ifdef __MY_TEST__
struct BayesNetwork *nb=NULL;

nb = (struct BayesNetwork *)malloc(sizeof(struct BayesNetwork));
TestInitNB(nb);

free(nb);
#else
struct BayesNetwork nb;
TestInitNB(&nb);
#endif
}


如果你爱C语言,请你爱指针; 如果你爱指针,请你爱指针的指针;
2007-08-10 09:38
legend2003cn
Rank: 1
等 级:新手上路
帖 子:6
专家分:0
注 册:2007-8-10
收藏
得分:0 
回复:(young)#include
运行通过,多谢了!
2007-08-10 23:12
快速回复:程序可以编译通过,但是运行exe文件的时候,却出现错误而终止
数据加载中...
 
   



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

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