The add_after() function should complement the list after detecting the string a_word[] with the string a_word_after[] . Both lines are entered by the user after filling out the list.
The compiler points to the marked line and writes:
error: incompatible types in assignment of 'char *' to 'char [80]'
I understand that it is impossible to assign a pointer to a character to an array of characters? But is a one-dimensional array not a pointer to the zero element of this array? Please explain how to fix it?
#include <iostream> #include <stdlib.h> #include <string.h> struct node { char word[80]; node* ptrToNextNode; }; void fillList(node *&list); void prntList(node *list); void makeList(node *&list); void add_after(node *list,char a_word[],char a_word_after[]); using namespace std; int main() { node* list; char a_word[80],a_word_after[80]; fillList(list); prntList(list); cout<<"Input a_word: "; cin>>a_word; cout<<"Input a_word_after: "; cin>>a_word_after; add_after(list,a_word,a_word_after); prntList(list); return 0; } void fillList(node*& list) { makeList(list); cout<<"Input word end press 'Enter'(input '.' for exit): "; cin>>list->word; if(!strcmp(".",list->word)) { delete list; list=NULL; } node *current, *last; current=list; while(current!=NULL) { last=new node; cout<<"Input word end press 'Enter'(input '.' for exit): "; cin>>last->word; if(!strcmp(".",last->word)) { delete last; last=NULL; } current->ptrToNextNode=last; current=last; } } void makeList(node *&list) { list=new node; if(list==NULL) { cout<<"Not enough memory! Terminate program..."; exit(1); } cout<<"List ready\n"; } void prntList(node *list) { if(list==NULL) { cout<<"This list is empty\n"; } else { while(list!=NULL) { cout<<list->word<<endl; list=list->ptrToNextNode; } cout<<"//////////End of list//////////"; } } void add_after(node *list,char a_word[],char a_word_after[]) { if(list==NULL) { cout<<"This list is empty"; } else { while(list!=NULL) { if(!strcmp(list->word,a_word)) { node* filling_pointer; makeList(filling_pointer); filling_pointer->word=a_word_after; //<---------------Ошибка в этой строке filling_pointer->ptrToNextNode=list->ptrToNextNode; list->ptrToNextNode=filling_pointer; } list=list->ptrToNextNode; } cout<<"//////////Pasting over//////////"; } }