why this code gives error message ?

#include <stdio.h>

#define GRAYSCALE
void set_pixel_data(int depth, void *p);

struct pixel_gray { char m; };
struct pixel_color { char r; char g; char b; };

int main()
{
struct pixel_gray pg;
struct pixel_color pc;
#ifdef GRAYSCALE
set_pixel_data( 1, &pg);
#else
set_pixel_data( 3, &pc);
#endif

return(0);
}

void set_pixel_data(int depth, void p)
{
struct pixel_gray p1;
switch(depth)
{
case 1:
p1=(struct pixel_gray
)p; //here is issue why??

break;
case 3:
printf("33");
break;
default:
printf("nothing he he ");
break;
}
}

what is the error?

p1=(struct pixel_gray*)p; //here is issue why??p1 is not a pointer.

Hi,

Please read the first post in any forum entitled how to use this forum.
http://forum.arduino.cc/index.php/topic,148850.0.html .
Then look down to item #7 about how to post your code.
It will be formatted in a scrolling window that makes it easier to read.

Thanks.. Tom... :slight_smile:

wounder1:

case 1:

p1=(struct pixel_gray*)p;    //here is issue why??

That should be:

case 1:
p1 = *(struct pixel_gray*)p;

johnwasser:
That should be:

case 1:

p1 = (struct pixel_gray)p;

He shouldn't be casting things to void* in the first place.

Pieter