第16.3.3 小节代码 维护零件数据库
//This is a comment
//Author:King
//Time:2020/12/10
//Reference:C Programming:A Modern Approach,Second Edition
/*******************************************************************************
16.3.3 小节代码 维护零件数据库,学习关于结构体的用法
********************************************************************************/
#include <stdio.h>
#include <string.h>
#include <ctype.h>
//#include <stdbool.h> // C99 only
//#include <time.h>
//#include <stdlib.h>
#define NAME_LEN 25 //单词的最长长度
#define MAX_PARTS 100 //最多元件数
struct part{
//定义一个零件数据库结构体,结构数组形式(元素为结构体的数组)
int number; //编号
char name[NAME_LEN + 1]; //零件名称
int on_hand; //现有数量
}inventory[MAX_PARTS];
int num_parts = 0; //当前数组中零件的数量
/* 函数声明*/
int read_line(char str[], int n); //读入单词到数组
int find_part(int number); //根据编号查找数组中零件信息
void insert(void); // 增加新零件
void search(void); // 搜索零件
void update(void); // 跟新零件信息
void print(void); // 显示零件信息
/*主函数*/
int main(void)
{