求助:为数组赋值过后程序出错……

dugufengwu 2010-12-07 08:12:59
在一个类里面有几个无符号整形变量,一个4维数组,FILE类型指针文件。

在为4维数组赋初值之后,会影响到之后的对类中其他内容的操作,出现错误。

如在给数组赋值成功后,txt文件无法打开。如果注释掉数组赋值代码,txt文件又能够开。

这个问题困扰我一天了,求高人指教。
...全文
126 6 打赏 收藏 转发到动态 举报
写回复
用AI写文章
6 条回复
切换为时间正序
请发表友善的回复…
发表回复
3h随然吧 2010-12-07
  • 打赏
  • 举报
回复
数组越界呀,类的对象分配的内存在一块,这样使得File指针的值改变了。所以文件打不开
qq120848369 2010-12-07
  • 打赏
  • 举报
回复
没什么可说的,接分.
dugufengwu 2010-12-07
  • 打赏
  • 举报
回复
[Quote=引用 3 楼 bluewanderer 的回复:]
for ( int tid=0; tid!=5; tid++)
?
[/Quote]

大哥,我错了。
在声明那应该是5,写成4了。
找了这么多人看了都没发现,CSDN好地方啊。
bluewanderer 2010-12-07
  • 打赏
  • 举报
回复
for ( int tid=0; tid!=5; tid++)
?
dugufengwu 2010-12-07
  • 打赏
  • 举报
回复
#include "Segment.h"


#define strcasecmp _stricmp
#define equal(a,b) (!strcasecmp((a),(b)))



int main(int argc, char** argv)
{
if ( argc==1)
{
printf( "-time <encoder log file> <output file>\n");
return 0;
}

SegmentationAnalysis* pcSegAnalysis = new SegmentationAnalysis;
if ( argc==5 && equal( argv[1], "-time") )
{
int length = atoi( argv[2] );
pcSegAnalysis->setTimeSegmentLength( length );
pcSegAnalysis->setEncdoerLog( argv[3] );
pcSegAnalysis->setTimeOutput( argv[4] );
pcSegAnalysis->ReadEncoderLog();
pcSegAnalysis->WriteTimeOutput();
}

return 0;
}

#ifndef _SEGMENT_H_
#define _SEGMENT_H_

#include <fstream>
#include <iostream>
#include <stdlib.h>
#include <stdio.h>
#include <assert.h>
#include <string>

#define BUFFER 128
#define MAX_SEGMENT_NUM 190

using namespace std;

typedef unsigned int UInt;

//const UInt buffer_size = 128;
//const UInt max_segment_num = 500; //I defined it 10000 before, but can work.

class SegmentationAnalysis
{
public:
SegmentationAnalysis();
virtual ~SegmentationAnalysis();

void ReadTrace();
void ReadEncoderLog();
void WriteTimeOutput();

void setEncdoerLog( char* EncoderLog ) { m_cEncoderLog = EncoderLog;}
void setTimeOutput( char* TimeOutput ) { m_cTimeOutput = TimeOutput;}
void setTimeSegmentLength( int length) { m_uiTimeSegmentLength = length;}
void setSizeSegmentLength( int length) { m_uiSizeSegmentLength = length;}
// string setTrace() const { return m_cTrace; }

private:
string m_cTrace;
string m_cEncoderLog;
string m_cTimeOutput;

UInt m_uiTimeSegmentLength; //segments have equal time, represent the number of Frames.
UInt m_uiSizeSegmentLength; //segments have equal size, in bits.

UInt m_uiGOPSize;
UInt m_aaaaTimeSegmentPieceSize[2][4][2][50]; //DTQ

FILE* m_pcTraceFile;
FILE* m_pcEncoderLogFile;
FILE* m_pcTimeOutputFile;
};

#endif

#include "Segment.h"


SegmentationAnalysis::SegmentationAnalysis()
:m_cTrace ()
,m_cEncoderLog ()
,m_cTimeOutput ()
,m_uiGOPSize (16)
,m_uiTimeSegmentLength ()
,m_uiSizeSegmentLength ()
,m_pcEncoderLogFile ( 0 )
,m_pcTimeOutputFile ( 0 )
{
}

SegmentationAnalysis::~SegmentationAnalysis()
{
}

void
SegmentationAnalysis::ReadEncoderLog()
{
//for ( int lid=0; lid!=2; lid++)
//{
// for ( int tid=0; tid!=5; tid++)
// {
// for( int qid=0; qid!=2; qid++)
// {
// for ( int segment_num=0; segment_num!=50; segment_num++)
// {
// m_aaaaTimeSegmentPieceSize[lid][tid][qid][segment_num] = 0;
// }
// }
// }
//}


m_pcEncoderLogFile = fopen( m_cEncoderLog.c_str(), "r");
if ( !m_pcEncoderLogFile )
{
printf( "Can not open %s!", m_cEncoderLog.c_str());
assert(0);
}

char c_Buffer[ BUFFER ];
char* c_Mark_AU = "AU";
memset( c_Buffer, 0, sizeof(c_Buffer) );

while( fgets(c_Buffer, 128, m_pcEncoderLogFile) )
{
if(strstr( c_Buffer, c_Mark_AU))
break;
}

UInt ui_FrameId = 0;
UInt ui_PreFrameId = 0;
UInt ui_TId;
UInt ui_LId;
UInt ui_QId;
UInt ui_SliceDataSize;
// UInt ui_GOPID;
UInt ui_SegmentNum = 0;
while( fgets(c_Buffer, 128, m_pcEncoderLogFile) )
{
ui_PreFrameId = ui_FrameId;
sscanf(c_Buffer+3,"%5d: %*2s T%1d L%1d Q%1d QP%*3d Y%*8s U%*8s V%*s %8d bit\n",&ui_FrameId, &ui_TId, &ui_LId, &ui_QId, &ui_SliceDataSize);//slicedata size can't get, result in overflow in array below...
if ( 0==(ui_FrameId-m_uiGOPSize)%m_uiTimeSegmentLength && ui_FrameId!=ui_PreFrameId)
{
ui_SegmentNum++;
}
m_aaaaTimeSegmentPieceSize[ui_LId][ui_TId][ui_QId][ui_SegmentNum] += ui_SliceDataSize/8; //convert to Byte.

if ( 3000==ui_FrameId )
{
break;
}
}
fclose( m_pcEncoderLogFile );
}

void
SegmentationAnalysis::ReadTrace()
{

}

void
SegmentationAnalysis::WriteTimeOutput()
{
m_pcTimeOutputFile = ::fopen( m_cTimeOutput.c_str(), "wt");
if ( !m_pcTimeOutputFile )
{
printf( "Can not open %s!", m_cTimeOutput.c_str());
assert(0);
}
for ( int lid=0; lid!=2; lid++)
{
for ( int tid=0; tid!=5; tid++)
{
for( int qid=0; qid!=2; qid++)
{
fprintf( m_pcTimeOutputFile, "%d%d%d", lid, tid, qid);
for ( int segment_num=0; segment_num!=50; segment_num++)
{
if ( 0==m_aaaaTimeSegmentPieceSize[lid][tid][qid][segment_num] )
{
fprintf( m_pcTimeOutputFile, "\n");
continue;
}
fprintf( m_pcTimeOutputFile, "%d", m_aaaaTimeSegmentPieceSize[lid][tid][qid][segment_num]);
}
}
}
}

fclose( m_pcTimeOutputFile );
}

代码来了。问题就在那注释了的4个for循环那。

就想叫yoko 2010-12-07
  • 打赏
  • 举报
回复
贴代码吧
4维数组?
你真厉害
代码下载地址: https://pan.quark.cn/s/8236006bf1f9 Word精灵插件:一款用于增强Microsoft Word功能的辅助软件,能够将多种复杂功能转化为插件形式,并在软件状态栏中进行展示,涵盖诸如批注管理、表格处理、内容替换、文档拆分、数学运算、字符提取、批量重命名等多项实用工具。在工作环境中应用该插件能够显著降低工作强度,提升操作效率。Word精灵插件兼容32位与64位的Microsoft Word版本,支持Word 2007、2010、2013以及Word 2016操作系统,但不适用于Word 2003版本。此外,该插件同样支持WPS办公软件。 功能概述: 1、表格自动调整宽度:自动优化文档内所有表格的显示宽度。 2、批量导出批注信息:将文档内所有批注集中导出到Excel工作簿中。 3、表格至Excel多表导出:在将表格导出到Excel时,每个Word表格将独立存放在一个工作表中,Word文档内的表格数量与Excel生成的工作表数量相等,并附有工作表目录。 4、表格至Excel单表导出:将文档内所有表格整合后导出到一个Excel工作表中,多个表格将按顺序排列于同一工作表内。 5、统一图片分辨率:对指定文件夹内的所有图片进行分辨率标准化处理。 6、图片批量缩放:依据设定比例对图片进行放大或缩小,支持按百分比调整。 7、图片批量插入:将图片批量插入到当前文档,可选择图片名称的展示形式,并设定图片的高度。 8、图片格式统一转换:将指定文件夹内的所有图片转换为相同的文件格式。 9、内容批量替换:对文档内容、页眉及页脚执行批量替换操作,例如将数字1替换为字母A,数字2替换为字母B,数字3替换为字母C等。 10、图片批量导出:将文档内所...
打开链接下载源码: https://pan.quark.cn/s/245ca7a27256 OmniGraffle是一款效能卓越的图形设计软件,在构建图表、流程图以及组织结构图等领域的应用尤为突出。该软件起源于Mac操作系统,并且兼容iOS平台,作为专业人士及业余爱好者进行图形设计时的首选工具之一。在OmniGraffle的功能模块中,“泳道图流程图”占据着核心地位,它主要用于勾勒业务流程图或系统流程图,其中各个分隔的泳道象征着不同的职能角色、部门划分或工作流程的各个阶段。泳道图(Lanes Diagram)作为流程图的一种特殊形式,通过将流程中的各个操作步骤分配到垂直或水平的“泳道”之中,能够明确地揭示出每个参与方或部门所承担的责任以及整个流程的走向。此类图形通常应用于业务流程管理(BPM)和系统分析领域,旨在帮助用户深入理解并优化复杂的业务流程。 在OmniGraffle中构建泳道图时,由于软件本身并未提供现成的泳道图模板,用户需要自行设计图形和布局以模拟出泳道的效果。然而,您提供的"06stencil泳道图流程图.graffle"文件很可能是一个预先构建好的模板,能够显著简化这一过程。该模板可能包含了预先设计好的泳道形态、箭头以及其他流程图组件,使用户能够直接在此基础上进行修改和增添个人的步骤,从而节省了大量的设计时间。 应用OmniGraffle的泳道图模板,你可以: 1. **导入模板**:首先需要启动OmniGraffle并将"06stencil泳道图流程图.graffle"文件添加到你的项目工作中。 2. **定制泳道**:依据实际需求调整泳道的数量和尺寸,使之契合你的业务流程。每个泳道对应一个角色或部门,确保它们的排列顺序和宽度能够精确地体现实际的工...

65,213

社区成员

发帖
与我相关
我的任务
社区描述
C++ 语言相关问题讨论,技术干货分享,前沿动态等
c++ 技术论坛(原bbs)
社区管理员
  • C++ 语言社区
  • encoderlee
  • paschen
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
  1. 请不要发布与C++技术无关的贴子
  2. 请不要发布与技术无关的招聘、广告的帖子
  3. 请尽可能的描述清楚你的问题,如果涉及到代码请尽可能的格式化一下

试试用AI创作助手写篇文章吧