Input Char in Doubly Linkedlist C

This is my code

struct Node{
    int data;

    char nim[12];

    struct Node *next, *prev;
};
struct Node *head, *tail;

void init(){
   head = NULL;
   tail = NULL;
}

int isEmpty(struct Node *h){
    if(h==NULL)
        return 1;
    else
        return 0;
}

void addData(char *nimI){

struct Node *baru;
baru = malloc(sizeof *baru);

baru->nim = malloc(12 * sizeof(char));
strcpy(baru->nim, nimI);
baru->next = NULL;
    baru->prev = NULL;
    if(isEmpty(head)==1){
        head=baru;
        tail=baru;
    }else{
        tail->next=baru;
        baru->prev=tail;
        tail = baru;
    }

    printList(head);
}

int main()
{
  char nimI[12];
  printf("NIM          : "); scanf("%[^\n]#", &nimI); fflush(stdin);
  addData(nimI);
}

I want to input char in my doubly linkedlist, but it's error. This code using C language

error : assigment to expression with array type (error in baru->nim = malloc(12 * sizeof(char));)



Read more here: https://stackoverflow.com/questions/66327023/input-char-in-doubly-linkedlist-c

Content Attribution

This content was originally published by Sylvia Helmi at Recent Questions - Stack Overflow, and is syndicated here via their RSS feed. You can read the original post over there.

%d bloggers like this: