Good, I have a problem in C, I want to cast a float to a void * and then in another function to cast it from void * to float, the problem is that it is printing 0.0. For what is this?
char * i = "1.22";
float numeroFlotante = (float) strtod(i,NULL); //Hace un cast de un char* a float
insertarInstruccion(&numeroFlotante, 3); //3 se refiere al tipo de dato, en este caso float.
void insertarInstruccion(void* valor, int tipo){
//ACA INSERTA ESTE DATO Y OTROS EN UNA ESTRUCTURA (PILA).
}
void imprimirPila(){
struct Pila *temp = pPila;
while (temp != NULL){
if(temp->tipo == 0){ //Si el tipo es 0 es int
int z = (int) temp->dato;
printf("%i\n", z);
}
else if(temp->tipo == 3){ //ACA ME IMPRIME 0,0.
float valor = *(float*) &temp->dato;
printf("%f\n",valor);
}
else{
printf("%s\n", (char*) temp->dato);
}
temp = temp->sig;
}
}