下面展示一些 内联代码片
。
// A code block
var foo = 'bar';
// An highlighted block
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define MAX_PRODUCTS 100
typedef struct {
int id;
char name[50];
char category[50];
char production_date[20];
int shelf_life;
char last_stock_date[20];
int stock;
double price;
} Product;
typedef struct {
Product products[MAX_PRODUCTS];
int count;
int totalStock; // 记录总库存量
} Inventory;
void initInventory(Inventory *inventory) {
inventory->count = 0;
inventory->totalStock = 0;
}
void addProduct(Inventory *inventory, Product product) {
if (inventory->count < MAX_PRODUCTS) {
product.id = inventory->count + 1;
inventory->products[inventory->count++] = product;
inventory->totalStock += product.stock; // 更新总库存量
printf("商品添加成功。\n");
} else {
printf("仓库已满,无法添加更多商品。\n");
}
}
void displayProduct(Product product) {
printf("商品名: %s\n", product.name);
printf("所属类别: %s\n", product.category);
printf("生产日期: %s\n", product.production_date);
printf("保质期: %d天\n", product.shelf_life);
printf("最新入库时间: %s\n", product.last_stock_date);
printf("库存量: %d\n", product.stock);
printf("价格: %.2f\n", product.price);
}
void searchProductByName(Inventory inventory, char *name) {
int found = 0;
for (int i = 0; i < inventory.count; i++) {
if (strcmp(inventory.products[i].name, name) == 0) {
displayProduct(inventory.products[i]);
found = 1;
}
}
if (!found) {
printf("未找到该商品。\n");
}
}