-1

I've seen some other posts have the same question; However the other posts recommended using strcpy(). The problem is that I am using strcpy() and I am still getting this error. I would really appreciate it if someone could help me out on this one. Ill post my structure and the code that I am having trouble with.

struct movie {
struct movie* next;
struct actor* actors;
char name[100];
int rating;
genre type;
}*list = NULL;

struct actor {
struct actor* next;
char name[100];
};


// Here is the code block i am having troubles with   

int add_actor(char* movie_name, char* actor_name)
{
struct movie *temp = list;
struct movie *actor = (struct movie *) malloc(sizeof(struct movie));

while (temp != NULL)
{
    if ((strcmp(temp->name, movie_name) == 0))
    {
        strcpy(list->actors->name, actor_name);
        return 1;
    }

    temp = temp->next;
}

return 0;

}

Jordanthedud
  • 61
  • 1
  • 6

1 Answers1

0

i guess struct actor is a linked list as is movie; if so here is the code

int add_actor(char* movie_name, char* actor_name)
{
    struct movie *temp = list;
    struct actor *actor=NULL;

    while (temp != NULL){
        if ((strcmp(temp->name, movie_name) == 0)){
            actor = calloc(sizeof(struct actor));
            strcpy(actor->name, actor_name);
            if(temp->actors){
                actor->next=temp->actors;
                temp->actors=actor;
            }else{
                temp->actors=actor;
            }
            return 1;
        }
        temp = temp->next;
    }
    return 0;
}
milevyo
  • 2,165
  • 1
  • 13
  • 18