C programming
/********************************************************* * From C PROGRAMMING: A MODERN APPROACH, Second Edition * * By K. N. King * * Copyright (c) 2008, 1996 W. W. Norton & Company, Inc. * * All rights reserved. * * This program may be freely distributed for class use, * * provided that this copyright notice is retained. * *********************************************************/ /* inventory2.c (Chapter 17, page 434) */ /* Maintains a parts database (linked list version) */ #include <stdio.h style="box-sizing: border-box; color: rgb(102, 102, 102); font-family: 'Open Sans', sans-serif; font-size: 13px; font-style: italic; line-height: 20px; background-color: rgb(251, 251, 251);">#include <stdlib.h style="box-sizing: border-box;">#include "readline.h" #define NAME_LEN 25 struct part { int number; char name[NAME_LEN+1]; int on_hand; struct part *next; }; struct part *inventory = NULL; /* points to first part */ struct part *find_part(int number); void insert(void); void search(void); void update(void); void print(void); /********************************************************** * main: Prompts the user to enter an operation code, * * then calls a function to perform the requested * * action. Repeats until the user enters the * * command 'q'. Prints an error message if the user * * enters an illegal code. * **********************************************************/ int main(void) { char code; for (;;) { printf("Enter operation code: "); scanf(" %c", &code); while (getchar() != '\n') /* skips to end of line */ ; switch (code) { case 'i': insert(); break; case 's': search(); break; case 'u': update(); break; case 'p': print(); break; case 'q': return 0; default: printf("Illegal code\n"); } printf("\n"); } } /********************************************************** * find_part: Looks up a part number in the...
10 years ago
Purchase the answer to view it
- c_programming.txt