My task is to store list of films in one array and store actor name in other array and make sure that film name is pointing to the respective actor. I'm using linked list. I'm facing difficulty in storing the address of the actor into the movie structure so that it can point to it. The code is in c. Please help!
struct movie
{
char name[10];
struct movie *data;
struct movie *next;
};
typedef struct movie m;
m *insert(m *first, char actor[10], int i)
{
m *cur;
cur = (m *)malloc(sizeof(m));
printf("\nEnter movie name: ");
scanf("%s", cur->name);
printf("\nEnter actor name: ");
scanf("%s", actor);
cur->data = &actor;
cur->next = first;
printf("\n%d", &actor);
printf("\n%d", cur->data);
printf("\n%s", actor);
printf("\n%s", *cur->data);
return (cur);
}
int main()
{
m *first = NULL, *ptr = NULL, *ptr1;
char actor[10];
int i = 0, ch;
first = (m *)malloc(sizeof(m));
ptr = (m *)malloc(sizeof(m));
do
{
printf("\n1.Enter movie: ");
printf("\n2.Search movie: ");
printf("\n3.Exit");
printf("\nEnter your choice: ");
scanf("%d", &ch);
switch(ch)
{
case 1:
first = insert(first, actor, i);
break;
case 2:
if(first == NULL)
{
printf("\nList Empty!");
break;
}
else
{
printf("\nEnter movie name: ");
scanf("%s", ptr->name);
ptr1 = first;
while(ptr1->next != NULL)
{
if(strcmp(ptr->name, first->name)==0)
{
printf("\n%s", &ptr->data);
break;
}
else
{
printf("\nNot found");
}
ptr1 = ptr1->next;
}
}
break;
}
}while(ch != 3);
}