c - 错误: Unknown type name

标签 c

我是模块化编程的新手,希望你能帮助我:) 这是我的 .c .h: 项目.h

#define L 31
#define L1 11
typedef struct{
    int priority;
    char service_type[L];
    char client_code[L1];
}*Item;
Item New_client();

项目.c

#include <stdio.h>
#include <stdlib.h>
#include "item.h"
Item New_client(){
    Item new_c=malloc(sizeof new_c);
    printf("Inserire priorita': "); scanf("%d",&new_c->priority);
    printf("Inserire servizio: "); scanf("%s",new_c->service_type);
    printf("Inserire codice cliente: "); scanf("%s",new_c->client_code);
    return new_c;
}

PQ.h

typedef struct Nodo *link;
struct Nodo{
    Item item;
    link next;
};
void init(link coda);
int empty_(link coda);
link insert_(link h,Item client);

PQ.c

#include <stdio.h>
#include <stdlib.h>
#include "PQ.h"

因此,当我将 PQ.h 包含在 PQ.c 中时,我收到错误:来自 CodeBlocks 的未知类型名称“Item”...我不明白为什么以及我能做什么来解决该问题。

最佳答案

您应该在 PQ.h 中包含 item.h:

#include "item.h"

typedef struct Nodo *link;
struct Nodo{
    Item item;
    link next;
};
void init(link coda);
int empty_(link coda);
link insert_(link h,Item client);

更新:关于错误:“Item”类型冲突 这是因为预处理器包含 item.h 两次。您应该使用 #ifndef __HEADER_NAME__#define __HEADER_NAME__#endif 组合来包装 header 。看看如何对 item.h 进行操作:

#ifndef __ITEM_H__
#define __ITEM_H__

#define L 31
#define L1 11
typedef struct{
    int priority;
    char service_type[L];
    char client_code[L1];
}*Item;
Item New_client();

#endif //__ITEM_H__

关于c - 错误: Unknown type name,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33963300/

相关文章:

c - 解释程序的输出

c - 指针字符的操作顺序

c - 如何将 char* 分配给函数内的结构成员?

c - 给定一个无序列表,返回列表中不存在的值

c - VS 代码片段未显示在 ctrl+space 上(但用户定义显示)

无法打印 C 中的返回值

python - BST 还是哈希表?

c - Netbeans 8.1 C 调试器错误?

c - 在c源代码中使用dll的效率

c - 使用 workqueue 或 kthread 在 Linux 内核中执行 ELF