How to initialize a char[50] to empty at struct constructor

1
2
3
4
5
6
struct my_struct {
int var1;
...
char[50] txt1;
my_struct(){txt1=""}
};


I'm unable to initialize txt1 to empty value....
Heeeelp

I need this, because when write to file I discover that I have uninitialized strange data.

Thanks
Last edited on
memset( txt1, 0, sizeof( txt1 ) );
closed account (DSLq5Di1)
char txt1[50] = {};

err whoops.. for a class,

1
2
3
4
5
6
struct my_struct {
int var1;
...
char txt1[50];
my_struct() : txt1() {} // use an initializer list
};
Last edited on
Nothing .....
can't compile no combination I write.....

1
2
3
4
5
6
7
8
struct my_struct {
 int var1;
 char txt[50];
 my_struct(){
 var1=0; 
 txt = ??????????  
 };
};


I'd want to initializa txt to zero characters (empty), or 50 blank spaces.
I remain needing help ......
Thnaks
What about this?

1
2
3
4
5
6
7
8
struct my_struct {
   int var1;
   char txt[50];
   my_struct(){
      var1=0; 
      memset( txt, 0, sizeof(txt) );
   };
};
memset is ok .
Thanks
Topic archived. No new replies allowed.