Skip to main content
JHERI
Associate III
February 8, 2019
Question

initialise structure array ??

  • February 8, 2019
  • 2 replies
  • 701 views

hello

I have a structure array

typedef struct
 {
 uint8_t Line_Add[lcd_lines];
 char Line_Data [banks] [lcd_lines] [40]; 
 uint8_t Data_Pos [lcd_lines]; 
 uint8_t Start_Pos [lcd_lines]; 
 uint32_t Flash_Bit [lcd_lines]; 
 uint8_t Alt_Flash_CharPos[lcd_lines]; 
 } lcd_module;

is there anyway I can set some default values to

uint8_t Line_Add[lcd_lines]; i.e ={1,2,3,4}

I don't know how to set some initial value to member array in a structure

any help as always much appreciated

regards

    This topic has been closed for replies.

    2 replies

    Piranha
    Principal III
    February 8, 2019

    Read the C language basics! Arrays, structs and unions are initialized with { } and can be hierarchical.

    lcd_module my_lcd = {
    	.Line_Add = {1, 2, 3, 4},
    	// Other members
    };

    JHERI
    JHERIAuthor
    Associate III
    February 9, 2019

    thank you

    have ready many post on array and struct but was getting a little confused, your example was clear and precise and made sense.

    Its clear now that you have to init the members of the instance of the structure being used, not the global structure level.

    thank you