[問題] 記憶體溢位?
小弟在寫程式的時候,寫道下列程式片段的時候
如果random_30()乘上一個數字,產生出來結果,好像最後會讓影像溢位
如果沒有成上數字好像就沒差,知道問題在下面,可是不知道怎麼解決。
會不會是unsigned char 跟 int 相加會有問題?
煩請各位高手指點了@_@
vector<vector<unsigned char> > image_array(m, vector<unsigned char>(n));
for ( int i = 0 ; i< m ;i++ ){
for ( int j = 0 ; j< n; j++ ){
fin >> image_array[i][j];
//亂數部分
random_n=random_30();
outtxt << random_n << endl;
fix=image_array[i][j]+random_n;
if (fix>255)
image_array[i][j]=255;
if (fix>=0 && fix <=255)
image_array[i][j]=fix;
if (fix<0)
image_array[i][j]=0;
//亂數部分結束
fout << image_array[i][j];
}
}
///////////////////////////////////////
int random_30()
{
int Cell[12];
int c;
int sum;
sum=0;
for(c=0;c<12;c++)
{
Cell[c]=10*rand()/RAND_MAX;
sum+=Cell[c];
}
sum=sum-54.0;
return sum;
}
--
※ 發信站: 批踢踢實業坊(ptt.cc)
◆ From: 114.40.28.65
推
05/21 13:08, , 1F
05/21 13:08, 1F
→
05/21 13:57, , 2F
05/21 13:57, 2F
推
05/21 15:28, , 3F
05/21 15:28, 3F
→
05/21 20:46, , 4F
05/21 20:46, 4F
→
05/22 13:45, , 5F
05/22 13:45, 5F
→
05/22 13:48, , 6F
05/22 13:48, 6F
→
05/29 20:42, , 7F
05/29 20:42, 7F
→
05/29 20:43, , 8F
05/29 20:43, 8F
C_and_CPP 近期熱門文章
PTT數位生活區 即時熱門文章