Im trying to implement a program using a bi-dimensional array of linked lists, to store lists of products and their quantity. For now, i've only done functions do add and show what's inside the list of the first array element t[0][0]. There's no error's when I add the product name and quantity, but when I try to show the list, I get no result. Can you check if im making some mistakes? Thanks for the help.
typedef struct object product, *pprod;
struct object{
char name[100];
int quantity;
pprod next;
};
product t[4][3];
int is_empty(pprod p)
{
if(p == NULL)
return 1;
else
return 0;
}
void show_info(pprod p)
{
while(p != NULL)
{
printf("%s\t%d\n",
p->name, p->quantity);
p = p->next;
} }
void get_data(pprod p)
{
printf("name: ");
scanf("%s",p->name);
printf("quantity: ");
scanf("%d",&p->quantity);
p->next = NULL;
}
pprod insert_beginning(pprod p)
{
pprod new;
if((new = malloc(sizeof(product))) == NULL)
printf("Error allocating memory\n");
else
{
get_data(new);
new->next = p; } p = new;
return p;
}
int main(int argc, char *argv[]){
insert_beginning(t[0][0].next);
show_info(t[0][0].next);
printf("%d",is_empty(t[0][0].next));
}