ok during this program whenever i try to display this "inventory" i get a string of numbers that doesnt match the numbers inputted...
heres the structure for the inventory
Code:
typedef struct
{
int day;
int month;
int year;
} DATE_S;
typedef struct
{
char bname[MAXN]; /* brand name */
char bcomp[MAXN]; /* bottling company */
int qty; /* quantity in stock */
double cost; /* the current cost of the item */
DATE_S date; /* the date of the last shipment */
double price; /* the selling price of the item */
} ITEM_S;
heres the function for adding the inventory:
Code:
void add_new_item(ITEM_S items[], int *pnitem)
{
ITEM_S *pnew;
char *p;
char buf[MAXN];
if ( *pnitem >= MAXITEMS )
{
printf("Out of memory [ Max items in list %d]\n", MAXITEMS);
return;
}
pnew = &items[*pnitem];
/* 1 */
for ( ; ; )
{
printf("Enter brand name [Enter to abort] \n");
if ( fgets(pnew->bname, MAXN, stdin) == NULL )
return;
if ( pnew->bname[0] == '\n' )
return;
if ( p = strrchr(pnew->bname, '\n') )
*p = '\0';
if ( find_item_in_list(items, *pnitem, pnew) )
printf("Brand name already in list\n");
else
break;
}
/* 2 */
printf("Enter bottling company\n");
fgets(pnew->bcomp, MAXN, stdin);
if ( p = strrchr(pnew->bcomp, '\n') )
*p = '\0';
/* 3 */
printf("Enter quantity in stock\n");
fgets(buf, MAXN, stdin);
pnew->qty = atoi(buf);
/* 4 */
printf("Enter the current cost of the item\n");
fgets(buf, MAXN, stdin);
pnew->cost = atoi(buf);
/* 5 */
printf("Enter the selling price of the item \n");
fgets(buf, MAXN, stdin);
pnew->price = atoi(buf);
/* 6 */
printf("Enter the day of the last shipment \n");
fgets(buf, MAXN, stdin);
pnew->date.day = atoi(buf);
printf("Enter the month of the last shipment \n");
fgets(buf, MAXN, stdin);
pnew->date.month = atoi(buf);
printf("Enter the year of the last shipment \n");
fgets(buf, MAXN, stdin);
pnew->date.year = atoi(buf);
++*pnitem;
printf("\n\n");
}
heres the function for displaying the code...
Code:
void print_list(ITEM_S items[], int nitem)
{
int i;
if ( nitem == 0 )
printf("The list is empty\n\n");
else
for ( i = 0 ; i < nitem ; ++i )
printf("%8s %8s %4d %2d %2d %d/%d/%d\n",
items[i].bname, items[i].bcomp, items[i].qty, items[i].cost,items[i].price,
items[i].date.day,
items[i].date.month,
items[i].date.year);
printf("\n");
}
anybody know why the numbers arent saving correctly?