0

我有以下main.c文件:

#include <stdio.h>
#include <stdlib.h>
#include <wctype.h>

#include "lista.h"

int main(int argc, char *argv[])
{
    struct nod *root = NULL;
    root = init(root);

    return 0;
}

lista.h

#ifndef LISTA_H_INCLUDED
#define LISTA_H_INCLUDED

#include "lista.c"

typedef struct nod
{
    int Value;
    struct nod *Next;
}nod;

nod* init(nod *);
void printList(nod *);

#endif // LISTA_H_INCLUDED

最后是lista.c,即:

#include<stdio.h>
#include<conio.h>
#include<stdlib.h>

#include "lista.h"

nod* init(nod *root)
{
    root = NULL;
    return root;
}

void printList(nod *root)
{
    //We don't want to change original root node!
    nod *aux = root;

    printf("\n=== Printed list =====\n");
    while (aux != NULL)
    {
        printf(aux->Value);
        aux = aux->Next;
    }
    puts("\n");
}

即使在包含头文件之后,我也会收到三个错误,上面写着: 未知类型名称“点头”

如何使 lista.h 中的 typedef 可以在 lista.c 上看到?

我只是无法弄清楚这里发生了什么。

4

1 回答 1

4

看看你的lista.h头文件:

#ifndef LISTA_H_INCLUDED
#define LISTA_H_INCLUDED

#include "lista.c"

[..]

#endif // LISTA_H_INCLUDED

您包括lista.c,您根本不应该这样做。并且发生错误,因为当时nod尚未定义。

于 2015-07-09T20:31:04.360 回答