Hello, I have been trying to send different data types to a function that receives them as a void* argument, but I cannot get it run (only with int's and chars). That's what I'm trying to do
Code:
#include <stdio.h>
void sample(short t,void *data)
{
switch(t)
{
case 0:
{
printf("INT=%d\n",(int*)data);
}
break;
case 1:
{
printf("FLOAT=%f\n",(float*)data);
}
break;
}
}
int main()
{
int ii;
float ff;
ii=27;
sample(0,(int*)ii);
ff=0.24f;
sample(1,&ff);
getchar();
return 0;
}
The 'sample' function gets a definition of the type (0->int, 1->float), and a void* value. The first call it works well, but on the second call (with the float value) the output is 0.00000
It is possible to do that?
Thank's in advance.
Niara