my current code:
#include <stdio.h>
#include <string.h>
/*
struct Value {
int typ;
unsigned char vstring;
int vint;
float vfloat;
};
*/
struct Value {
int typ;
/*
type=1 ==> get vstring
type=2 ==> get int
type=3 ==> get float
*/
union{
struct{
unsigned char *vstring;
};
struct{
int vint;
};
struct{
float vfloat;
};
}
};
void clear(Value vall){
if(vall.typ == 1){
delete(vall.vstring);
}else if(vall.typ == 2){
delete(vall.vint);
}else{
delete(vall.vfloat);
}
}
int main()
{
struct Value v;
/////////////////////////////////////////////
v.typ=1;
strcpy( v.vstring,"C Programming/may this a very big utf-8 string!");
/*
strcpy( v.vint,4);
strcpy( v.vfloat,4.5);
*/
/////////////////////////////////////////////
printf( "ValueType : %d\n", v.typ);
printf( "ValueString : %s\n", v.vstring);
printf( "ValueInt : %d\n", v.vint);
printf( "ValueFloat : %f\n", v.vfloat);
return 0;
Value copy=v;
clear(copy);
copy.typ=2;
copy.vint=5;
}
but this have bug , and i not know how can fix this.
this have a Value
struct. in this have (vstring,vint,vfloat) , and type of value store in typ
for fast speed.
please help me to fix this code.
i will want store this struct in array/map/hashmap.... tank you.