-1

GCC コンパイラを使用して C でリンク リストを実装しようとしましたが、これらの警告が表示されました。私が受け取った警告のほとんどは、「互換性のないポインター型からの代入」でした。

linklist.c: In function 'insertatbegin':
linklist.c:20:8: warning: assignment from incompatible pointer type [enabled by default]
linklist.c:24:18: warning: assignment from incompatible pointer type [enabled by default]
linklist.c:25:8: warning: assignment from incompatible pointer type [enabled by default]
linklist.c: In function 'display':
linklist.c:37:7: warning: assignment from incompatible pointer type [enabled by default]

コードを実行した後、何も出力されません。

#include <stdio.h>
#include <string.h>
#include <conio.h>
#include <stdlib.h>
typedef struct 
{
int data;
struct node *next;
}node;
void insertatbegin(node **head,int item)
{
    node *nextnode=(node *)malloc(sizeof(node));
    if(nextnode!=NULL)
    {
        nextnode->data=item;
        nextnode->next=head;   //warning line 24
        head=nextnode;      // warning line 25
    }
    else
        printf("memory not allocated\n");

}

void display(node * head)
{
    node *temp=head;
    while(temp!=NULL)
    {
        printf(" %d  ",temp->data);
        temp=temp->next;   //warning line 37
    }
}

void main()
{
    node *head=NULL;

    insertatbegin(&head,20);
    insertatbegin(&head,30);
    insertatbegin(&head,40);
    display(head);
    getch();
}

それは正しいようですが、それから何も出力されませんでした。

4

1 に答える 1