This is yours, amended to work (as few changes as possible). I guess it does what you want.
Code:
#include <stdio.h>
#include <stdlib.h>
#define MAXchar 100
typedef struct
{
char name[50];
float price;
int noItems;
char expiry[50];
char type[50];
char detail[50];
} structure;
int addItems(structure inventory[], int *arrayL)
{
int i;
int z, n;
char buff1[MAXchar];
char buff2[MAXchar];
/* Stemplate(); */
printf("Please enter number of items you wish to enter: ");
scanf("%d", &z);
fflush(stdin);
printf("Please enter inventory items\n");
for (i = *arrayL, n = 0; n < z; i++, n++)
{
printf("Enter Item name: ");
gets(inventory[i].name);
printf("Enter Item price: ");
gets(buff1);
inventory[i].price = atoi(buff1);
printf("Enter number of Items: ");
gets(buff2);
inventory[i].noItems = atoi(buff2);
printf("Enter expiry (if applicable): ");
gets(inventory[i].expiry);
printf("Enter type of Item: ");
gets(inventory[i].type);
printf("Enter other Details: ");
gets(inventory[i].detail);
}
*arrayL = i;
return(1);
}
void PrintMe(structure *s)
{
printf
(
"Name: %s\nPrice: %f\nnoItems: %d\nexpiry: %s\ntype: %s\ndetail: %s\n",
s->name,
s->price,
s->noItems,
s->expiry,
s->type,
s->detail
);
}
int main(void)
{
structure inventory[1000];
int arrayL = 0;
int i;
addItems(inventory, &arrayL);
for (i = 0; i < arrayL; i++)
{
PrintMe(&inventory[i]);
}
return(0);
}