//functionality ---- Adding new entry //functionality ---- Printing the entry based on part number //functionality ---- Modifying on hand , given the part number //functionality ---- Print the the complete database //functionality ---- Terminate #include #define MAX_PARTS 100 struct part { int number; char name[40]; int on_hand; }dbcreation[MAX_PARTS]; int num_parts = 0; int find_part(int); void insert(void); void search(void); int find_part(int part_no) { int i; for(i=0;i< num_parts;i++) if(dbcreation[i].number == part_no) return i; return -1; } void insert(void) { int part_number; if(num_parts == MAX_PARTS){ printf("Database is full; can't add more parts\n"); return; } printf("Enter part number : "); scanf("%d",&part_number); if(find_part(part_number)>=0) { printf("\n Part already exists \n"); //exit(0); return; } dbcreation[num_parts].number = part_number; printf("Enter part name : "); //gets(dbcreation[num_parts].name); scanf("%s",dbcreation[num_parts].name); printf("Enter quantity on hand : "); scanf("%d",dbcreation[num_parts].on_hand); num_parts = num_parts + 1; printf("%d",num_parts); } void search(void) { int number,i; printf("Enter part number: "); scanf("%d",&number); i= find_part(number); if(i>=0) { printf("Part name : %s\n",dbcreation[i].name); printf("Enter quantity on hand: %d\n",dbcreation[num_parts].on_hand); } else printf("Part Not Found"); } int main() { char code; //char answer; //for(;;) { printf("You can perform the following Operations :\n "); printf("1. Insert a New Part (i)\n"); printf("2. Search operation (s)\n"); printf("3. Quit(q)\n"); printf("Enter operation code: "); scanf("%c",&code); while(getchar()!= '\n') ; switch(code){ case 'i': insert(); printf("%d",num_parts); printf("\n****Part Details inserted successfully !****\n"); break; case 's': search(); break; case 'q': return 0; break; default : printf("Please enter legal code\n"); } printf("\n"); //printf("Do you want to continue? (y or n)\n"); //scanf("%c",&answer); } }