void main(void)
{
struct item my_items[capacity];
int code = 0, x = 1;
printf("Please make a selection\n");
printf("1 ~ To key in data\n");
printf("2 ~ To calculate\n");
printf("4 ~ To exit\n");
while (x == 1)
{
printf("Your selection:");
scanf("%d", &code);
switch (code)
{
case 1:
input(my_items);
break;
case 2:
cal_item(my_items);
break;
case 3:
printf("\n");
printf("Thank You!Please come again,have a nice day ahead.\n");
printf("exiting in[3]\n"
"exiting in[2]\n"
"exiting in[1]\n"
"exiting in[0]\n");
x = 0;
break;
}
}
}
void input(struct item my_items[capacity])
{
int code = 0, option = 1, search_code, quantity, a = 1, b = 1, c = 0, k ;
char user_selection;
Add a case 4 that does what your current case 3 would do and implement a print function.
1 2 3 4 5 6 7 8 9 10 11
case 3:
output(my_items);
case 4:
printf("\n");
printf("Thank You!Please come again,have a nice day ahead.\n");
printf("exiting in[3]\n""exiting in[2]\n""exiting in[1]\n""exiting in[0]\n");
x = 0;
break;
Your print out function should look similar to this:
1 2 3 4 5 6 7 8
void output(struct item my_items[capacity])
{
int i = 0;
for(i;i<capacity;i++)
{
printf("%d\n%f\n%s\n%s",my_items[i].code,my_items[i].price,my_items[i].label,my_items[i].brand);
}
}
In order to print them in alphabetical order, you will have to add a sorting algorithm before printout. Possibly after they were input.
My suggestion would be use a quick sort algorithm or a bubble sort algorithm.