下面展示一些 内联代码片
。
// A code block
var foo = 'bar';
// An highlighted block
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define MAX_PRODUCTS 100
#define FILENAME "inventory.txt"
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 saveInventoryToFile(Inventory *inventory) {
FILE *file = fopen(FILENAME, "w");
if (file == NULL) {
printf("无法打开文件 %s\n", FILENAME);
return;
}
fprintf(file, "%d\n", inventory->count);
for (int i = 0; i < inventory->count; i++) {
fprintf(file, "%d,%s,%s,%s,%d,%s,%d,%.2f\n",
inventory->products[i].id,
inventory->products[i].name,
inventory->products[i].category,
inventory->products[i].production_date,
inventory->products[i].shelf_life,
inventory->products[i].last_stock_date,
inventory->products[i].stock,
inventory->products[i].price);
}
fclose(file);
printf("库存信息已保存到文件 %s\n", FILENAME);
}