写出一个可以实现对原神卡池物品的存储c代码
时间: 2024-06-03 20:07:20 浏览: 26
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define MAX_ITEMS 1000
typedef struct {
char name[50];
int rarity;
} Item;
typedef struct {
Item items[MAX_ITEMS];
int count;
} CardPool;
void add_item(CardPool *pool, Item item) {
if (pool->count < MAX_ITEMS) {
pool->items[pool->count] = item;
pool->count++;
}
}
void print_pool(CardPool pool) {
for (int i = 0; i < pool.count; i++) {
printf("%s (稀有度: %d)\n", pool.items[i].name, pool.items[i].rarity);
}
}
int main() {
CardPool pool = { .count = 0 };
Item item1 = { .name = "迪卢克", .rarity = 5 };
Item item2 = { .name = "温迪", .rarity = 5 };
Item item3 = { .name = "班尼特", .rarity = 4 };
add_item(&pool, item1);
add_item(&pool, item2);
add_item(&pool, item3);
print_pool(pool);
return 0;
}
相关推荐
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)