c 中结构体struct 的定义方式,举个简单的例子

来源:百度知道 编辑:UC知道 时间:2024/05/17 06:27:09
结构体数组,是数组~~~~~~~

#include<stdio.h>
struct st
{
char name[10]; //姓名
int age; //年龄
char sex[5]; //性别
};
void main()
{
int i;
st student[2];
for(i=0;i<2;i++)
scanf("%s%d%s",student[i].name,&student[i].age,&student[i].sex);
for(i=0;i<2;i++)
printf("%s,%d,%s\n",student[i].name,student[i].age,student[i].sex);
}

/*输入:
zhang 18 boy
wang 19 girl
输出:
zhang 18 boy
wang 19 girl

typedef struct tagStu {
...
}Stu;
Stu stus[100];

struct 结构体名
{
类型 变量名;
...
}结构体名;