结构体嵌套
1 //玩家 Player 2 //玩家有属性门派(种族,阵营) 3 4 #include<stdio.h> 5 #include<stdlib.h> 6 #include<string.h> 7 8 struct Martial //门派 9 { 10 int id; //门派 id 11 char name[50]; //门派m名称 12 int count; //门派人数 13 char type[50]; //门派的类型 正派 中立 邪派 14 15 16 }; 17 18 struct Player 19 { 20 int id; 21 char name[50]; //玩家名称 22 char pass[50]; //玩家的登录密码 23 char sex[10]; //玩家性别 男 M 女 X 24 25 struct Martial martial; //玩家的门派 26 27 28 }; 29 int main() 30 { 31 struct Player player = {1,"UZI","123456","M",{1,"RNG",500,"ADC"}}; 32 33 printf("%d\t %s\t %s\t %s\t %d\t %s\t %d\t %s\n",player.id,player.name,player.pass,player.sex,player.martial.id,player.martial.name,player.martial.count,player.martial.type); 34 35 }
本文来自博客园,作者:Bytezero!,转载请注明原文链接:https://www.cnblogs.com/Bytezero/p/15072639.html