PDA

View Full Version : Unable to initialize char [] var inside struct ....



tonnot
26th August 2011, 10:29
can't compile no combination I write.....


struct my_struct {
int var1;
char txt[50];
my_struct(){
var1=0;
txt = ??????????
};
};



I'd want to initialize txt to zero characters (empty), or 50 blank spaces.
I need help ......
Thanks

high_flyer
26th August 2011, 10:40
#define TXT_SIZE 50

struct my_struct {
int var1;
char txt[TXT_SIZE];
my_struct(){
var1=0;
memset(txt,0,sizeof(char)*TXT_SIZE);
}
};