写一段初始化结构体程序
时间: 2023-10-06 15:10:22 浏览: 25
Sure, I can help you with that! Here's an example of an initialization program for a struct in C:
```
#include <stdio.h>
// Define the struct with its fields
struct person {
char name[50];
int age;
float height;
};
int main() {
// Declare an instance of the struct
struct person john;
// Initialize the fields of the struct
strcpy(john.name, "John Doe");
john.age = 30;
john.height = 1.75;
// Print the values of the struct fields
printf("Name: %s\n", john.name);
printf("Age: %d\n", john.age);
printf("Height: %.2f\n", john.height);
return 0;
}
```
This program initializes a struct called `person` with three fields: `name`, `age`, and `height`. It then declares an instance of the struct called `john` and initializes its fields with some example values. Finally, it prints out the values of the struct fields using `printf()`.