level 3
叶瑜之清流者
楼主
在编译过程中它显示了第二个结构里面的都初始化失败,去度娘也没有看懂,想问一下大神们,为什么会初始化失败了
#include <stdio.h>
#include <stdlib.h>
/* 商品结构 */
typedef struct _prop
{
int id; //道具的唯一编号
char name[50]; //道具名称
double price; //道具单价
int stock; //库存量,如果在背包中,表示此道具的叠加数量
char desc[200]; //道具功能的描述
}Prop;
/* 背包结构 */
typedef struct _bag{
int playerid; //所属玩家的编号
int count; // 当前背包中,道具的数量
int max; //当前背包的插槽总数 --插槽数量可以让玩家自己购买
Prop props[8]; //当前背包的道具数组
}Bag;
/* 玩家结构 */
typedef struct _player{
int id; //玩家编号
char name[50]; //用户名、昵称
char pass; //密码
Bag bag; //玩家的背包
double gold; //玩家金币-人性化显示
double sysee; //元宝数量
}Player;
Prop *props;
Player *players;
int propsCount = 0;
int playersCount = 0;
void Init();
void ShowProps();
void Showplayers();
int main()
{
Init();
ShowProps();
return 0;
}
void Init()
{
static Prop propArray[] = {
{1, "双倍经验卡", 3000, 10, "双击666"},
{2, "大宝剑", 5000, 8, "嘤嘤嘤"},
{3, "生锈的铁剑", 8000, 9, "ohhhhhhh"},
{4, "除草功能", 9000, 2, "直接爽入你的灵魂"},
{5, "神仙斗法套装", 99999, 1, "双击666"},
};
propsCount = sizeof(propArray) / sizeof(Prop);
props = propArray; //设定指针指向
static Player playerArray[] = {
{1, "串串超人", "123456", .gold = 50000},
{2, "bow", "123456", .gold = 100000},
{3, "王建国", "123456", .gold = 59000},
{4, "张前进", "123456", .gold = 580000},
};
playersCount = 5;
players = playerArray;//设置players指针指向
}
void ShowProps()
{
int i;
if (props == NULL) return;
printf("编号\t名称\t单价\t库存\t商品介绍\n");
for (i = 0; i < propsCount; i++)
{
printf("%d\t%s\t%.2lf\t%d\t%s\n", props[i].id, props[i].name, props[i].price, props[i].stock, props[i].desc);
}
}
void Showplayers()
{
}

2018年01月31日 07点01分
1
#include <stdio.h>
#include <stdlib.h>
/* 商品结构 */
typedef struct _prop
{
int id; //道具的唯一编号
char name[50]; //道具名称
double price; //道具单价
int stock; //库存量,如果在背包中,表示此道具的叠加数量
char desc[200]; //道具功能的描述
}Prop;
/* 背包结构 */
typedef struct _bag{
int playerid; //所属玩家的编号
int count; // 当前背包中,道具的数量
int max; //当前背包的插槽总数 --插槽数量可以让玩家自己购买
Prop props[8]; //当前背包的道具数组
}Bag;
/* 玩家结构 */
typedef struct _player{
int id; //玩家编号
char name[50]; //用户名、昵称
char pass; //密码
Bag bag; //玩家的背包
double gold; //玩家金币-人性化显示
double sysee; //元宝数量
}Player;
Prop *props;
Player *players;
int propsCount = 0;
int playersCount = 0;
void Init();
void ShowProps();
void Showplayers();
int main()
{
Init();
ShowProps();
return 0;
}
void Init()
{
static Prop propArray[] = {
{1, "双倍经验卡", 3000, 10, "双击666"},
{2, "大宝剑", 5000, 8, "嘤嘤嘤"},
{3, "生锈的铁剑", 8000, 9, "ohhhhhhh"},
{4, "除草功能", 9000, 2, "直接爽入你的灵魂"},
{5, "神仙斗法套装", 99999, 1, "双击666"},
};
propsCount = sizeof(propArray) / sizeof(Prop);
props = propArray; //设定指针指向
static Player playerArray[] = {
{1, "串串超人", "123456", .gold = 50000},
{2, "bow", "123456", .gold = 100000},
{3, "王建国", "123456", .gold = 59000},
{4, "张前进", "123456", .gold = 580000},
};
playersCount = 5;
players = playerArray;//设置players指针指向
}
void ShowProps()
{
int i;
if (props == NULL) return;
printf("编号\t名称\t单价\t库存\t商品介绍\n");
for (i = 0; i < propsCount; i++)
{
printf("%d\t%s\t%.2lf\t%d\t%s\n", props[i].id, props[i].name, props[i].price, props[i].stock, props[i].desc);
}
}
void Showplayers()
{
}

