Monday
Tuesday
Wednesday
Thursday
Friday
Tatuday
Sunday
//AAAAAAAAAAAA
//11111111
/* 1)定义结构体的同时,定义数组
struct Student
{
int age;
char *name;
int s_no;
float score;
}stu[5];
2)先定义结构体,后定义数组
struct Student boy[5];
*/
/*
#include<stdio.h>
int main()
{
struct Student
{
int age;
char *name;
int s_no;
float score;
}stu[5];
struct Student boy[5];
return 0;
}
*/
//2222222222
#include<stdio.h>
#include<string.h>
int main()
{
//结构体数组的初始化方法
//1、定义结构体数组的时候,进行初始化
struct Student
{
char name[20];
int age;
}boys[3]={
{"sb",18},
{"zbz",38},
{"cgx",28}};
//2、定义的同时进行初始化
struct Student girls[2]={
{"fengjie",18},
{"cjk",28}};
/*
这个也对
//3、先定义后初始化
struct Student ds[2];
ds[0]=(struct Student){"xzmly",18};
ds[1]=(struct Student){"bdjy",18};
*/
//4、先定义结构体数组,后初始化
struct Student stu[2];
//stu[0].name = "zhangsan"
//strcpy(stu[0].name="zhangsan");
scanf("%s",stu[0].name);
stu[0].age = 19;
//BBBBBBBBBBBBBBB
//结构数组的遍历
for(int i=0;i<3;i++){
printf("name:%s,age:%d\n",boys[0].name,boys[i].age);
}
return 0;
} |
|