错误:取消引用指向不完整类型“链接{aka结构链接}”的指针

时间:2019-04-08 20:03:49

标签: c pointers struct header

这是我所拥有的,但无济于事    links.h

//tried __LINK_H__ also
#ifndef __LINK_INCLUDE__
#define __LINK_INCLUDE__
typedef struct links Links;
extern Links *new_link(Links*,int);
#endif

links.c

#include<stdio.h>
#include<stdlib.h>
#include"links.h"
struct links{
    int data;
    struct links* next;
};

Links *new_link(Links* head, int val){

    Links *temp = malloc(sizeof(Links));
    temp->data = val;
    temp->next = NULL;
    if(head == NULL){
        head = temp;
    }
    return head;

}

lmain.c

#include<stdio.h>
#include "links.h"

void main(){

    Links * head = NULL;
    head = new_link(head,89);

    //i get error at this printf
    //error: dereferencing pointer to incomplete type ‘Links {aka struct links}’
    printf("%s",head->data);
}

任何帮助都会很棒 操作系统是ubuntu,请全部帮助linux。 我应该从哪里开始或寻找 我已经在这里呆了两天了

0 个答案:

没有答案