I have a question for strcpy

Asked 2 years ago, Updated 2 years ago, 97 views

 C
//Enter your code here
#include <stdio.h>
#include <stdlib.h>

typedef int element;
typeef structure DListNode { // Dual Connection Node Type
    element data;
    struct DListNode* llink;
    struct DListNode* rlink;
} } DListNode;

// Initialize dual connection list
void init(DListNode* phead)
{
    phead->llink = phead;
    phead->rlink = phead;
}

// Output a node in a dual connection list
void print_dlist(DListNode* phead)
{
    DListNode* p;
    for (p = phead->rlink; p != phead; p = p->rlink) {
        printf("<-| |%d| |-> ", p->data);
    }
    printf("\n");
}
// Insert new data to the right of the node before.
void dinsert(DListNode *before, element data)
{
    DListNode *newnode = (DListNode *)malloc(sizeof(DListNode));
    strcpy(newnode->data, data);
    newnode->llink = before;
    newnode->rlink = before->rlink;
    before->rlink->llink = newnode;
    before->rlink = newnode;
}
// Delete the node removed.
void ddelete(DListNode* head, DListNode* removed)
{
    if (removed == head) return;
    removed->llink->rlink = removed->rlink;
    removed->rlink->llink = removed->llink;
    free(removed);
}

// Dual Connection List Test Program
int main(void)
{
    DListNode* head = (DListNode *)malloc(sizeof(DListNode));
    init(head);
    printf ("Additional Steps\n");
    int i = 0;
    for (i = 0; i < 5; i++) {
        // Insert to the right of the head node
        dinsert(head, i);
        print_dlist(head);
    }
    printf("\nDelete step\n");
    for (i = 0; i < 5; i++) {
        print_dlist(head);
        ddelete(head, head->rlink);
    }
    free(head);
    return 0;
}

Hello, I have a question because I couldn't move on to the next step due to a code error during the assignment.

If you run the full code above, the error appears in line 31 saying incompatible implicit discrimination of built-in function 'strcpy'.

(The corresponding line inserts // new data to the right of the node before. Below.)

strcpy(newnode->data,data); should I change this?<

c data-structure

2022-09-22 10:46

1 Answers

The function strcpy is declared in string.h.

You have to explicitly include it.

#include <string.h>


2022-09-22 10:46

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.