Welcome to collectivesolver - Programming & Software Q&A with code examples. A website with trusted programming answers. All programs are tested and work.

Contact: aviboots(AT)netvision.net.il

Buy a domain name - Register cheap domain names from $0.99 - Namecheap

Scalable Hosting That Grows With You

Secure & Reliable Web Hosting, Free Domain, Free SSL, 1-Click WordPress Install, Expert 24/7 Support

Semrush - keyword research tool

Boost your online presence with premium web hosting and servers

Disclosure: My content contains affiliate links.

39,945 questions

51,887 answers

573 users

How to initialize a structure in C

1 Answer

0 votes
#include <stdio.h>
#include <string.h>

typedef struct {
  char str[16];
  int n;
  float f;
} STExample;

int main() {
  STExample a = { "abc", 9098, 3.14f }; 
  printf("%s %d %f\n", a.str, a.n, a.f);

  STExample b = { "", 8472, 8.912f }; 
  strcpy(b.str, "xyz");
  printf("%s %d %f\n", b.str, b.n, b.f);

  return 0;
}



/*
run:

abc 9098 3.140000
xyz 8472 8.912000

*/

 



answered Jun 7, 2024 by avibootz

Related questions

2 answers 201 views
201 views asked Jun 9, 2015 by avibootz
2 answers 134 views
1 answer 153 views
1 answer 115 views
1 answer 116 views
116 views asked Aug 23, 2021 by avibootz
1 answer 139 views
139 views asked Aug 22, 2021 by avibootz
...