C: Incompatible type when assigning to type char[] from type char * -


struct name {     char name[256];     struct name* next; };  void display(struct name *head) {     struct name *ende = head;      int = 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 compiler error when want write temp->name in temp->next->name ! can explain me why following error : "incompatible types when assigning type char[256] char*" , how can solve problem ? i´m new c.

you can't assign array, initialize on definition.

you can copy array:

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

read strcpy here.


Comments

Popular posts from this blog

get url and add instance to a model with prefilled foreign key :django admin -

android - Keyboard hides my half of edit-text and button below it even in scroll view -

css - Make div keyboard-scrollable in jQuery Mobile? -