// this is program designed to create Cd data base

#include <stdio.h>
#include <string.h>
#include <stdlib.h>

//=============================================
//LINKED LIST USED FOR CREATING THE DATABASE CD
//=============================================
struct CD_type_node
{
   int CDnum;
   char title[20];
   int CDcount;
   struct CD_type_node* next;
};

struct Artist_type_node // to create a linked list of CD's
{
   struct CD_type_node CD_data;
   char Artist_name[20];
   struct Artist_type_node* next;

};


// ===================
//FUNCTION PROTOTYPES
//====================

struct CD_type_node* insert(struct CD_type_node* temp);
struct CD_type_node* delete_CD(struct CD_type_node*temp1);

int main()
{
   struct CD_type_node* mylist; // this points to the first node of the linked list
   mylist = (struct CD_type_node*)malloc(sizeof(struct CD_type_node)); // allocate space for the CD database linked list

   int i;
   for (i = 0; i < 100; i++)
   {
      struct Artist_type_node;
   }

   printf(" 1) Stock new CD\n 2) print details of CD\n 3)search CD\n 4) Sell a CD\n 5) Quit\n");

   int menu = 5;

   while (menu >= 1 && menu <= 5)
   {
      scanf("%d", &menu);

      if (menu == 1)
      {
         mylist = insert(mylist);
      }

      if (menu == 2)
      {
         printf("works2");

      }

      if (menu == 3)
      {
         printf("works3");

      }

      if(menu == 4)
      {
         printf("works4");

      }

      if (menu == 5)
      {
         printf("works5");
      }

      if (menu > 5 || menu < 1)
      {
         printf("invalid range..... put a number between 1-5\n");
         scanf("%d", &menu);
      }
   }


   free(mylist);
   return 0;
}

struct CD_type_node* insert(struct CD_type_node* temp)
{
   struct CD_type_node* CDlist = temp;

   int num, count;
   char name[20], artist[20];


   printf(" 1) Aritst name: \n 2) CD title: \n 3) CD number: \n 4) The Amount to be stocked: \n");

   scanf("%s",artist);
   CDlist->Artist_name[20] = artist[20];

   scanf("%s", name);
   CDlist->title[20] = name[20];

   scanf("%d", &num);
   CDlist->CDnum = num;

   scanf("%d", &count);
   CDlist->CDcount= count;

   printf("%s\n %d\n %d\n", CDlist->title, CDlist->CDnum, CDlist->CDcount);
}

this is partial of the project:
1) Create a CD_type_node structure having the following fields:
CD number
CD title
CD count
A pointer to CD_type_node to point to next CD.

2) Create a Artist_type_node structure having the following fields:
Artist’s name
A pointer to a CD_type_node, to enable you to create a linked list for CDs.

3) In your main, create an array of type Artist_type_nodes that can store up to 100 elements.

Thus, your database will be an array of 100 Artists, where each Artist has a list of CDs. Basically, each Artist’s name and a pointer to the list of CD’s will be stored in the Artist_Array.

------------------------------
when i compile this is what it tells me: struct CD_type_node has no element Artist_name

how do i make the correct linked list and how do i create the array

// this is program designed to create Cd data base

#include <stdio.h>
#include <string.h>
#include <stdlib.h>

//=============================================
//LINKED LIST USED FOR CREATING THE DATABASE CD
//=============================================
struct CD_type_node
{
   int CDnum;
   char title[20];
   int CDcount;
   struct CD_type_node* next;
};

struct Artist_type_node // to create a linked list of CD's
{
   struct CD_type_node CD_data;
   char Artist_name[20];
   struct Artist_type_node* next;

};

when i compile this is what it tells me: struct CD_type_node has no element Artist_name

how do i make the correct linked list and how do i create the array

Where is Artist_name defined? Is it in CD_type_node?

Where is Artist_name defined? Is it in CD_type_node?

no its created as a separate linked list node, atleast that's how i understand it, i do not know if its right.. because the assignment says create a CD_type_node and create Artist_type node with a pointer to CD_type_node. i dont know if its a struct within a struct because that didnt work as well

no its created as a separate linked list node, atleast that's how i understand it, i do not know if its right.. because the assignment says create a CD_type_node and create Artist_type node with a pointer to CD_type_node. i dont know if its a struct within a struct because that didnt work as well

A struct within a struct is not a pointer to a struct. See my emphasis in your post...

You need a field, like next, that points to a CD Node. The address of the proper CD Node goes into this pointer in the Artist Node.

// this is program designed to create Cd data base

#include <stdio.h>
#include <string.h>
#include <stdlib.h>

//=============================================
//LINKED LIST USED FOR CREATING THE DATABASE CD
//=============================================
struct CD_type_node
{
   int CDnum;
   char title[20];
   int CDcount;
   struct CD_type_node* next;
};

struct Artist_type_node // to create a linked list of CD's
{
   struct CD_type_node* CD_node;
   char Artist_name[20];
};

int main()
{
    struct Artist_type_node artists[100];
    // extra code here
    mylist = insert(mylist, struct Artist_type_node *artists);

}

thats what i changed, the problem is, it wont let me pass the struct as an argument to a function. isnt that the correct syntax for sending a struct to a function

mylist = insert(mylist, struct Artist_type_node *artists);

Did you try

mylist = insert(mylist, *artists);

:icon_question:

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.