viewing paste Unknown #17532 | Text

Posted on the
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108
//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<stdio.h>
#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);
        }
}
 
Viewed 378 times, submitted by unknown.