| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 285 人关注过本帖
标题:请教了,查了两天的错误,请查阅
只看楼主 加入收藏
ZKelvin
Rank: 1
等 级:新手上路
帖 子:1
专家分:0
注 册:2007-9-11
收藏
 问题点数:0 回复次数:1 
请教了,查了两天的错误,请查阅
程序模块在Debug模式下,运行是正常的,但是运行时却说内存错,不能read~~
代码如下:
========================
Class Keyword_Record{
#ifndef KEYWORD_RECORD_H
#define KEYWORD_RECORD_H
#include "SMS.H"

// 关键词类,类中定义了一个关键词所包含的数据:
// 汉字字符串+汉字的个数+拼音类别码(整型数组)+控制标志串
class Keyword_Record
{
private:
char Key_WD[21]; //中文字符串10个定义
int Key_Num; //中文汉字的个数
int *Class_ID; //对应汉字拼音类别代码数组,10个int数值
char *Flag; //存储10位控制标志位

public:
// class constructor
Keyword_Record();
~Keyword_Record();
Keyword_Record(char *str1,char *str2);
void Set_PYID(int n,int* IDArray);
void Print_Meb();
char* Get_Key();
int Get_Size();
int * Get_ID_Array();

};
Keyword_Record::Keyword_Record(){};
Keyword_Record::Keyword_Record(char* strkey,char* flagstr){
//Keyword=str1;
strcpy(Key_WD,strkey);
//cout<<Key_WD<<endl;
//system("pause");
Key_Num=int(strlen(Key_WD)/2); //汉字个数,一个汉字两个字节
//cout<<Key_Num<<endl;
//system("pause");
//strcpy(Flag,flagstr); //这个不对,两个都是字符串指针,不能strcpy??
Flag=new char[10];
strcpy(Flag,flagstr);

//cout<<Key_WD<<""<<Flag<<endl;
//system("pause");
/********以下处理拼音代码数组************************/
Class_ID=new int[Key_Num];
//int *Class_ID=new int[Key_Num]; //是重定义了吗?导致内存
for (int i=0;i<Key_Num;i++){
Class_ID[i]=-1;
//cout<<Class_ID[i]; //initialize all zero firest;
}
cout<<"Constructor Ok!"<<endl;
};
//******************************************
void Keyword_Record::Set_PYID(int n,int* IDArray){
for(int i=0;i<n;i++){
Class_ID[i]=IDArray[i];
}

}
/******************/
void Keyword_Record::Print_Meb(){
cout<<Key_WD<<" ,HZ_Num="<<Key_Num<<",Class_ID:";
for(int i=0;i<Key_Num;i++)
cout<<Class_ID[i]<<"+";
cout<<",Flag:"<<Flag<<endl;
}
// class destructor
Keyword_Record::~Keyword_Record(){};
char* Keyword_Record::Get_Key(){return Key_WD;}
int Keyword_Record::Get_Size(){return Key_Num;}
int* Keyword_Record::Get_ID_Array(){return Class_ID;}


#endif // KEYWORD_RECORD_H

}
/////////////////////////////////////////////////////////////////


Keyword_Record *Keyword_Lib_A;
main(){
......

extern Keyword_Record * Keyword_Lib_A;
Keyword_Lib_A = new Keyword_Record[Keyword_Lib_Size];
//for (int i=0;i<100;i++){
// Keyword_Lib_A[i]=Keyword_Record("","");
// }
if (Keyword_Lib_A == NULL){
cout<<"Memory Allocated Error!"<<endl;
system("pause");
exit(1);
}
.....
//以下是一个函数模块在 Main中被调用,目的是从文件读取,来初始化对象数组Keyword_Lib_A[]
#include "SMS.H"
//#include "py_dic_record.h"
#include "Keyword_Record.h"
//#include "py_index_record.h"
#include <iostream>
#include <fstream>
#include <string>
#include <stdlib.h>

using namespace std;

//void Init_Keyword_Lib(char *filename,Keyword_Record *Lib_Pointer){
void Init_Keyword_Lib_A(){

extern Keyword_Record * Keyword_Lib_A; //引用全局变量
//Keyword_Lib_A = new Keyword_Record[Keyword_Lib_Size];
//if (Keyword_Lib_A == NULL){
// cout<<"Memory Allocated Error!"<<endl;
// system("pause");
// exit(1);
// };
extern int Keyword_Lib_Size_A;
char *Keyword_File; //
char buffer[255]; //定义缓冲区,奇怪的是:不是255大小居然不行
char *tmp_HZ ;
char *tmp_FG ;

//if get file name ,outout here :
//Keyword_File=filename;
Keyword_File=Keyword_Lib_File_A;
cout<<"Keyword File is: ./"<<Keyword_File<<endl;
//system("pause");

ifstream in ;
in.open(Keyword_File);

if (!in){
cerr<<"Can't Open File Keyword_File_A"<<endl;
system("pause");
exit(1);
}
char delims[] = ","; //逗号作为分隔符
char *result = NULL;
int Flg=0; //偶数说明是获得的是关键词,奇数说明是控制位字符
int L=0;
//cout<<Keyword_Lib_Size_A<<endl;

while(in.getline(buffer,255)){
result = strtok( buffer, delims );

while( result != NULL ) { //一行结束是不是也就也会返回NULL
if (Flg %2 == 0 ){
tmp_HZ = result ; //获取关键词字符串 到临时变量
}
if (Flg %2 == 1 ){
tmp_FG = result ; //获取控制位字符串 到临时变量
}
Flg++; //下一段
result = strtok(NULL,delims);
}//一行结束 //end inner while
//Keyword_Lib_A[Line] = new Keyword_Record();
//cout<<tmp_HZ<<tmp_FG<<endl;
//cout<<"YES---------"<<Line_No<<endl;

cout<<L<<endl;
//Keyword_Record T(tmp_HZ,tmp_FG);
//T.Print_Meb();
//delete T;
//Keyword_Lib_A[L]=T;
//Keyword_Lib_A[L].Print_Meb();
Keyword_Lib_A[L] = Keyword_Record(tmp_HZ,tmp_FG);
L++;
}//end out while
in.close(); //关闭文件
in.clear();

//获得纯关键词库的大小
Keyword_Lib_Size_A=L;

//******验证数据**********
for (int k=0;k<Keyword_Lib_Size_A;k++){
Keyword_Lib_A[k].Print_Meb();
// cout<<"****"<<endl;
}


奇怪的现象是:Debug模式下,运行是正常的,但是退出运行exe程序时,就说是:“ox7c95426d”指令引用的"0x00000000"内存,改内存不能为read.....

而且,在文件Key_File_A.txt中的文本,如果是只有三行,也运行OK的,但是超过三行,就报同样的错误

请高手执教分析,在线等………………………………
谢谢各位~
搜索更多相关主题的帖子: 查阅 
2007-10-28 16:38
罚我不睡觉
Rank: 1
等 级:新手上路
帖 子:12
专家分:0
注 册:2007-10-5
收藏
得分:0 
........

2007-10-28 18:24
快速回复:请教了,查了两天的错误,请查阅
数据加载中...
 
   



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

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