当前位置: 代码迷 >> C语言 >> 程序可以编译通过,但是运行exe文件的时候,却出现错误而终止
  详细解决方案

程序可以编译通过,但是运行exe文件的时候,却出现错误而终止

热度:141   发布时间:2007-08-10 08:01:14.0
程序可以编译通过,但是运行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  

----------------解决方案--------------------------------------------------------

#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
}


----------------解决方案--------------------------------------------------------
回复:(young)#include
运行通过,多谢了!
----------------解决方案--------------------------------------------------------
  相关解决方案