C 错误:8.13802e+;06超出了类型为'的可表示值的范围;无符号字符';
接近终点时,我遇到了一个无法解决的问题。也许你们中的一个可以: 以下代码的编译工作正常,但当我启动程序时,会收到以下错误消息: helpers.c:228:42:运行时错误:8.13802e+06超出“unsigned char”类型的可表示值的范围 该代码是一个分块模糊图像的函数,但是第一个像素[0][0]没有得到正确的平均值,我不知道为什么会收到错误消息C 错误:8.13802e+;06超出了类型为'的可表示值的范围;无符号字符';,c,runtime,blur,cs50,C,Runtime,Blur,Cs50,接近终点时,我遇到了一个无法解决的问题。也许你们中的一个可以: 以下代码的编译工作正常,但当我启动程序时,会收到以下错误消息: helpers.c:228:42:运行时错误:8.13802e+06超出“unsigned char”类型的可表示值的范围 该代码是一个分块模糊图像的函数,但是第一个像素[0][0]没有得到正确的平均值,我不知道为什么会收到错误消息 // Blur image void blur(int height, int width, RGBTRIPLE imag
// Blur image
void blur(int height, int width, RGBTRIPLE image[height][width])
{
int i;
int j;
int m;
int n;
int averageRed;
int averageBlue;
int averageGreen;
RGBTRIPLE average[height][width];
// For each row of the image...
for (i = 0; i < height; i++)
{
//...take each pixel.
for (j = 0; j < width; j++)
//If current height equals 0 AND current width equals 0..
if (i == 0 && j == 0)
{
//..take 2 rows of the picture..
for (m = i; m <= i + 1; m++)
{
//..and take 2 pixels of each row.
for (n = j; n <= j + 1; n++)
{
//Sum up the rgb-values for each of the 2 pixel of the 2 rows.
averageRed = averageRed + image[m][n].rgbtRed;
averageGreen = averageGreen + image[m][n].rgbtGreen;
-> The error line averageBlue = averageBlue + image[m][n].rgbtBlue;
}
}
//Save the average of the values in a separate array after the 2x2 pixel-block
average[i][j].rgbtRed = round((float)averageRed / 4);
average[i][j].rgbtGreen = round((float)averageGreen / 4);
average[i][j].rgbtBlue = round((float)averageBlue / 4);
//Set average-variables to 0
averageRed = 0;
averageGreen = 0;
averageBlue = 0;
}
//From each row of the image...
for (i = 0; i < height; i++)
{
//...take each pixel..
for (j = 0; j < width; j++)
{
//...and update the original value with the temporary stored value.
image[i][j].rgbtRed = average[i][j].rgbtRed;
image[i][j].rgbtGreen = average[i][j].rgbtGreen;
image[i][j].rgbtBlue = average[i][j].rgbtBlue;
}
}
}
//模糊图像
无效模糊(整数高度、整数宽度、RGB三重图像[高度][宽度])
{
int i;
int j;
int m;
int n;
国际平均;
国际平均蓝;
国际平均绿色;
RGB三倍平均[高度][宽度];
//对于图像的每一行。。。
对于(i=0;i
解决方案非常简单,只是缺少了平均值/绿色/蓝色变量的初始化
未获取它,因为错误消息仅指向averageBlue
再次感谢M Oehm:-)太多的代码。请看。期望我们费力地阅读那么多代码是不合理的。对不起。我希望现在不要太短。您永远不会初始化或将avaraged
等重置为零,因此您会得到臭名昭著的“垃圾值”,在您的例子中是8.13802e+06。如何获得范围的运行时错误?另外,i
和j
也未初始化。抱歉,忘了在i和j初始化时插入for循环。@M Oehm:i do…se在错误行“将平均变量设置为0”下方。其他一切正常。唯一的问题是标记的“averageBlue”