0
votes
struct name {
    char name[256];
    struct name* next;
};

void Display(struct name *head) {
    struct name *ende = head; 
    int i = 1;
    printf("\nList of names:\n");
    while(ende != NULL) {
        printf("(%d) %s", i, ende->name);
        ende = ende->next;
        i++;
    }
}

void bubblesort(struct name *head) {
    struct name *block,*temp;
    char change[256] = "";
    for(block = head; block->next != NULL; block = block->next) {
        for(temp = head; temp->next != NULL; temp = temp->next) {
            if(temp->next == NULL)
                break;
            if(temp->next->name[0] < temp->name[0]) {
                char *element = temp->next->name;
                printf("ELEMENT: %s", element);
                temp->next->name = temp->name;
                temp->name = element;
            }
        }
    }
}

I don´t know why i get a compiler error when i want to write from temp->name in temp->next->name ! Can anyone explain to me why i get the following error : "incompatible types when assigning to type char[256] from char*" and how i can solve my problem ? I´m new to C.

1

1 Answers

3
votes

You can't assign to an array, only initialize it on definition.

You can however copy to an array:

strcpy(temp->next->name, temp->name);
strcpy(temp->name, element);

Read about strcpy here.