Results 1 to 2 of 2

Thread: Unable to initialize char [] var inside struct ....

  1. #1
    Join Date
    Sep 2010
    Posts
    654
    Thanks
    56
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Windows

    Default Unable to initialize char [] var inside struct ....

    can't compile no combination I write.....

    Qt Code:
    1. struct my_struct {
    2. int var1;
    3. char txt[50];
    4. my_struct(){
    5. var1=0;
    6. txt = ??????????
    7. };
    8. };
    To copy to clipboard, switch view to plain text mode 

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

  2. #2
    Join Date
    Jan 2006
    Location
    Munich, Germany
    Posts
    4,714
    Thanks
    21
    Thanked 418 Times in 411 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: Unable to initialize char [] var inside struct ....

    Qt Code:
    1. #define TXT_SIZE 50
    2.  
    3. struct my_struct {
    4. int var1;
    5. char txt[TXT_SIZE];
    6. my_struct(){
    7. var1=0;
    8. memset(txt,0,sizeof(char)*TXT_SIZE);
    9. }
    10. };
    To copy to clipboard, switch view to plain text mode 
    ==========================signature=============== ==================
    S.O.L.I.D principles (use them!):
    https://en.wikipedia.org/wiki/SOLID_...iented_design)

    Do you write clean code? - if you are TDD'ing then maybe, if not, your not writing clean code.

  3. The following user says thank you to high_flyer for this useful post:

    tonnot (26th August 2011)

Similar Threads

  1. Replies: 3
    Last Post: 15th July 2011, 20:43
  2. Replies: 5
    Last Post: 23rd June 2011, 08:31
  3. How to convert unsigned char[] to char *?
    By Gokulnathvc in forum Newbie
    Replies: 2
    Last Post: 29th April 2011, 08:58
  4. Better way to initialize QVector
    By lyucs in forum Newbie
    Replies: 3
    Last Post: 25th August 2009, 08:25
  5. char to const char* with atof
    By mickey in forum General Programming
    Replies: 5
    Last Post: 29th February 2008, 04:10

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Qt is a trademark of The Qt Company.