请教一下为什么会初始化失败了
c吧
全部回复
仅看楼主
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
level 3
[汗]
2018年01月31日 09点01分 2
level 5
可怕,这是个什么玩意,我的眼睛啊![滑稽][滑稽][滑稽][滑稽][滑稽]
2018年03月08日 23点03分 5
level 1
static Player playerArray[] = {
{1, "串串超人", "123456", .gold = 50000},
{2, "bow", "123456", .gold = 100000},
{3, "王建国", "123456", .gold = 59000},
{4, "张前进", "123456", .gold = 580000},
};
你这个,gold是什么东西,你在什么地方学到在初始化列表里面还有这种调用成员的写法
你的初始化列表可以比结构体中成员数量少,但是你这个顺序 也只能是根据结构体中变量的顺序来,但是你不能说中间一个成员不给值,跳过他给后面的成员初始值。
2018年03月09日 19点03分 6
level 1
这个读取不到值,是用list去存的值吗?
再者请提供其他这个页面代码。
你打断点调试了吗?
2018年05月08日 08点05分 8
level 7
char *pass;
2018年05月08日 09点05分 9
level 7
这设定看着好辣眼睛
2018年05月08日 09点05分 11
吧务
level 9
按照8楼的试试
2018年06月16日 23点06分 13
1