You can't dereference a void pointer. The typical way to represent a variable that can have multiple data types is to use a union. Here is some rough sample code.
Code:
typedef enum { DT_INT, DT_CHAR, DT_FLOAT } DATA_TYPE;
typedef struct {
DATA_TYPE dt;
union {
int intVal;
char charVal;
float floatVal;
} data;
} MULTI;
Code:
switch( i )
{
case( _INT ) : /* Allocate an integer memory space to the void pointer */
my_multi.dt = DT_INT;
my_multi.data.intVal = the_int;
break;
case( _CHAR ) : /* Allocate a char memory space to the void pointer */
my_multi.dt = DT_CHAR;
my_multi.data.charVal = the_char;
break;
case( _FLOAT ) : /* Allocate a float memory space to the void pointer */
my_multi.dt = DT_FLOAT;
my_multi.data.floatVal = the_float;
break;
default : printf( "\n\n" );
exit( 0 );
}
Code:
void PrintMulti(MULTI* pMulti)
{
switch(pMulti->dt)
{
case DT_INT:
printf("%d\n", pMulti->data.intVal);
break;
case DT_CHAR:
printf("%c\n", pMulti->data.charVal);
break;
case DT_FLOAT:
printf("%.2f\n", pMulti->data.floatVal);
break;
default:
printf("Unknown data type!\n");
}
}
For an example of a more complex multiple data type check out the Windows VARIANT.