社区
C++ 语言
帖子详情
求助:为数组赋值过后程序出错……
dugufengwu
2010-12-07 08:12:59
在一个类里面有几个无符号整形变量,一个4维数组,FILE类型指针文件。
在为4维数组赋初值之后,会影响到之后的对类中其他内容的操作,出现错误。
如在给数组赋值成功后,txt文件无法打开。如果注释掉数组赋值代码,txt文件又能够开。
这个问题困扰我一天了,求高人指教。
...全文
84
6
打赏
收藏
求助:为数组赋值过后程序出错……
在一个类里面有几个无符号整形变量,一个4维数组,FILE类型指针文件。 在为4维数组赋初值之后,会影响到之后的对类中其他内容的操作,出现错误。 如在给数组赋值成功后,txt文件无法打开。如果注释掉数组赋值代码,txt文件又能够开。 这个问题困扰我一天了,求高人指教。
复制链接
扫一扫
分享
转发到动态
举报
写回复
配置赞助广告
用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维数组?
你真厉害
java较全的面试题
一、Java基础部分 1. JAVA的基本数据类型有哪些 ? String 是不是基本数据类型 ? 2. 一个".java"源文件中是否可以包括多个类(不是内部类)?有什么限制? 3. Java有没有goto? 4. 说说&和&&的区别. 5. 在JAVA中如何跳出当前的多重嵌套循环? 6. switch语句能否作用在byte上,能否作用在long上,能否作用在Strin...
Shell编程实战范例
前言: 本部分主要参考此博客: https://www.w3cschool.cn/shellbook/uglqdozt.html 数值运算: 进制转换: 其他进制转换为10进制, 可以使用Shell内置的进制转换 如将8进制的11转换为10进制: echo "8to10 $[8#11]" 直接使用bc计算器, 能直接指定源&目标进制, 方便转换 由于bc是交互式的计算器, 所以这里没法直接使用参数的形式进行, 而是采用echo一个用分号分割的多条语句组成的字符串给bc, 其将自动打印结果 ec
从零基础入门Linux系统
从零基础入门Linux系统 目录 第一章:Linux简介 1 一、Linux是什么 1 二、Unix和Linux的发展史 1 三、开源软件介绍 4 四、Linux的应用场景 5 第二章:Linux安装和部署 8 一、 虚拟机的安装和使用 8 二、Linux的分区相关原理 16 三、CentOS 6.8的安装流程 20 四、CentOS 7.5 的安装流程 35 五、远程管理Linux操作系统 43 第三章:给初学者的Linux服务器管理建议 44 一、学习Linux的注意事项 44 二、服务器管理建议 46
C++ 学习拾遗 —— 点滴记录C++学习过程中遇到的问题以及整理
2013.5.28 delete []str; 今天在看老师课件的时候,看到析构函数里有一条语句: delete []str; 有印象,但一时想不起来。遂查询了一下。 解释: delete str1; //释放指针变量的内存 delete [] str1; //释放指针
数组
的内存(说是指针
数组
,也不是很准确) 指针
数组
: ...
linux_study_1
Linux系统下.ko文件是什么文件?.so文件是什么文件... 5 我有一个文件abc.txt,我想用bunzip2压缩工具进行压缩!... 5 insmod(installmodule)5 记mount NFS遇到的一个问题(-o nolock)6 关于C语言结构体
赋值
(LINUX内核风格). 6 sprintf格式... 8 sprintf格式... 8 标识符...
C++ 语言
64,646
社区成员
250,476
社区内容
发帖
与我相关
我的任务
C++ 语言
C++ 语言相关问题讨论,技术干货分享,前沿动态等
复制链接
扫一扫
分享
社区描述
C++ 语言相关问题讨论,技术干货分享,前沿动态等
c++
技术论坛(原bbs)
社区管理员
加入社区
获取链接或二维码
近7日
近30日
至今
加载中
查看更多榜单
社区公告
请不要发布与C++技术无关的贴子
请不要发布与技术无关的招聘、广告的帖子
请尽可能的描述清楚你的问题,如果涉及到代码请尽可能的格式化一下
试试用AI创作助手写篇文章吧
+ 用AI写文章