-1

I have this program in webots where I am extracting the color instance from the Wbcamerarecongnition and trying to print the color which according to documentation is made of 3D array for each color. below is link to the documentation

I am trying to execute the following

const WbCameraRecognitionObject objects;
printf(" %f ", objects.color);

however the code crashes when i do so. any advice I want to access the color of the construct WbCameraRecognitionObject.

Barmar
  • 741,623
  • 53
  • 500
  • 612
yosef ali
  • 33
  • 8
  • the link to documentation https://cyberbotics.com/doc/reference/camera?tab-language=c – yosef ali Feb 22 '22 at 21:06
  • 1
    There's no `color` member in `WbCameraRecognitionObject`. There's a pointer named `colors`. – Barmar Feb 22 '22 at 21:08
  • If the compiler gave you an error message and stopping compiling, say that. Do not describe it as “the code crashes.” When an executing program gets a fatal error and is terminated by the operating system or by the hardware, that is a crash. When a compiler detects an error in a program and chooses to stop compiling because that is how the compiler is designed, that is normal and proper behavior for the compiler and is not a crash. – Eric Postpischil Feb 22 '22 at 21:26

1 Answers1

2

color should be colors. But this is a pointer to an array of doubles, not a single value, so you need to index it. number_of_colors contains the size of the array.

for (int i = 0; i < objects.number_of_colors; i++) {
    printf(" %f ", objects.colors[i]);
}
printf("\n");
Barmar
  • 741,623
  • 53
  • 500
  • 612