Welcome to collectivesolver - Programming & Software Q&A. A website you can trust. I check, compile and run every program. Contact me at: aviboots(AT)netvision.net.il
Hostgator 1 Penny

BlueHost Web Hosting

Ecommerce Software - Best Ecommerce Platform Made for You - Free Trial

Ecommerce Software - Best Ecommerce Platform Made for You - Free Trial

getflywheel wordpress hosting


Distribute your Resume to 500+ Job Boards & Recruiters


6,849 questions

9,751 answers

573 users

How initialize an arrays of structures in C

1 Answer

0 votes
#include <stdio.h>

struct user
{
    float age;
    char  name[30];
};


int main(void) 
{
   struct user users[] = 
   {
             { .age = 41,
               .name = "Ash",  
             },
             { .age = 52,
               .name = "Axel",
             }
   };
   
   for (int i = 0; i < 2; i++)
   { 
        printf("users[%d].age = %.1f users[%d].name = %s\n", i, users[i].age, i, users[i].name);
   }
  
   return 0;
}
    
/*
run:
 
users[0].age = 41.0 users[0].name = Ash
users[1].age = 52.0 users[1].name = Axel

*/

 




answered Aug 27, 2017 by avibootz
...