-1

The execution stops automatically, when I execute the program. I access this function multiplyImages. The code is as followed

#include "rt_nonfinite.h"
#include "multiplyImage.h"

/* Function Declarations */
static double rt_roundd_snf(double u);

/* Function Definitions */
static double rt_roundd_snf(double u)
{
  double y;
  if (fabs(u) < 4.503599627370496E+15) {
    if (u >= 0.5) {
      y = floor(u + 0.5);
    } else if (u > -0.5) {
      y = u * 0.0;
    } else {
      y = ceil(u - 0.5);
    }
  } else {
    y = u;
  }

  return y;
}

void multiplyImage(const unsigned char img[/*2115216*/6], double parameter, unsigned
                   char imgout[/*2115216*/6])
{
  int i0;
  double d0;
  unsigned char u0;

  /*  implements a function that multiplies an image with a parameter */
  for (i0 = 0; i0 < 6; i0++)
  {
    d0 = rt_roundd_snf(parameter * (double)img[i0]);
    if (d0 < 256.0) 
    {
      if (d0 >= 0.0) {
        u0 = (unsigned char)d0;
      } else 
      {
        u0 = 0;
      }
    } else if (d0 >= 256.0)
    {
      u0 = MAX_uint8_T;
    } else
    {
      u0 = 0;
    }

    imgout[i0] = u0;
    Ou[i0] = imgout[i0];
  }
  printf(d0);

}

When the execution comes to printf, the execution automatically stops. The img[6] and imgout[6] are just dummy images created to test the working.. I am using this function in another main function as followed.

unsigned char test[6];

for (int c = 0; c < color; ++c)
    {
        for (int h = 0; h < height; ++h)
        {
            for (int w = 0; w < width; ++w)
            {
                x = 'R';
                Image_Conversion(c, h, w) = x;
                test[c*h*w] = Image_Conversion(c, h, w);
                std::cout << "Test:  " << test[c*w*h];
            }
        }
    }
multiplyImage(&(const unsigned char)test[6], 1, &test[6]);

It would be great if someone could guide me with the issue.

user3652437
  • 201
  • 2
  • 8

1 Answers1

2

"Execution automatically quits" seems to be an euphemism for "my program segfaults". d0 is of type double, and you should tell printf about that fact. Please try this code instead:

printf("%f", d0);
Axel
  • 13,939
  • 5
  • 50
  • 79