下面是一个简单的C语言程序示例,用于记录和管理服装的基本信息。为了简化,我将使用一个结构体来存储每件服装的信息,并使用数组来存储多件服装。为了唯一标识每件服装,我们可以使用一个递增的编码。 ```c #include #include // 定义服装信息的结构体 typedef struct { int id; // 唯一编码 char style[50]; // 款式 char size[10]; // 尺码 char color[20]; // 颜色 char material[50]; // 材质 } Clothing; // 定义服装数组的最大容量 #define MAX_CLOTHING 100 // 初始化一件服装信息 void initializeClothing(Clothing *c, int id, const char *style, const char *size, const char *color, const char *material) { c->id = id; strcpy(c->style, style); strcpy(c->size, size); strcpy(c->color, color); strcpy(c->material, material); } // 打印服装信息 void printClothing(const Clothing *c) { printf("ID: %d\n", c->id); printf("Style: %s\n", c->style); printf("Size: %s\n", c->size); printf("Color: %s\n", c->color); printf("Material: %s\n", c->material); printf("\n"); } int main() { Clothing clothingList[MAX_CLOTHING]; // 存储服装信息的数组 int clothingCount = 0; // 当前存储的服装数量 // 示例:添加几件服装到数组中 initializeClothing(&clothingList[clothingCount++], 1, "T-shirt", "M", "Red", "Cotton"); initializeClothing(&clothingList[clothingCount++], 2, "Jeans", "32", "Blue", "Denim"); initializeClothing(&clothingList[clothingCount++], 3, "Dress", "L", "Black", "Silk"); // 打印所有服装信息 for (int i = 0; i < clothingCount; i++) { printClothing(&clothingList[i]); } return 0; } ``` 这个程序定义了一个`Clothing`结构体来存储服装的信息,包括`id`、`style`、`size`、`color`和`material`。它还定义了一个`initializeClothing`函数来初始化服装信息,一个`printClothing`函数来打印服装信息,以及一个主函数`main`来演示如何添加和打印服装信息。在`main`函数中,我添加了三件服装作为示例,并打印了它们的信息。你可以根据需要扩展这个程序,比如从文件或用户输入中读取服装信息。

点赞(0)
×
关注公众号,登录后继续创作
或点击进入高级版AI
扫码关注后未收到验证码,回复【登录】二字获取验证码
发表
评论
返回
顶部