C 链接列表,路径到大小的应用无效不完整类型

C 链接列表,路径到大小的应用无效不完整类型,c,pointers,memory-management,struct,C,Pointers,Memory Management,Struct,我在编译代码时遇到了一个无效的应用程序大小路径错误,但我自己找不到问题,有人能帮忙吗 /********************************************************* * Node to represent a packet which includes a link reference* * a link list of nodes with a pointer to a packet Struct * ***********************

我在编译代码时遇到了一个无效的应用程序大小路径错误,但我自己找不到问题,有人能帮忙吗

/*********************************************************
* Node to represent a packet which includes a link reference*
* a link list of nodes with a pointer to a packet Struct    *

**********************************************************/
struct node {
unsigned int Source;
unsigned int Destination;
unsigned int Type;
int Port;
char *Data;
struct Packet *next;
 // Link to next packet

//unassigned int source
//unassigned int destination
//int type
//unassigned int port
//char *data
//struct node  *next link to next node
};

typedef struct Packet node; // Removes the need to constantly refer to struct


/*********************************************************
* Stubs to fully declared functions below                *
**********************************************************/
void Outpacket(node **head);
void push(node **head, node **aPacket);
node* pop(node **head);

int main() {

/*********************************************************
* pointers for the link list and the temporary packeyt to    *
* insert into the list                                   *
**********************************************************/
node *pPacket, *phead = NULL;

/*********************************************************
* Create a packet and also check the HEAP had room for it   *
**********************************************************/
pPacket = (node *)malloc(sizeof(node));
if (pPacket == NULL)
{
    printf("Error: Out of Memory\n");
    exit(1);
}
这只是完整代码的一部分,但断点发生在以下行:

pPacket = (node *)malloc(sizeof(node));

感谢您的帮助

这可能是因为您使用的是结构数据包,没有定义它

struct节点的定义中,您使用的是
struct-Packet*
。但是没有所谓的
struct-Packed
。要么更改结构的名称,要么更改元素

请尝试以下操作:

struct Packet {
unsigned int Source;
unsigned int Destination;
unsigned int Type;
int Port;
char *Data;
struct Packet *next;
 // Link to next packet

//unassigned int source
//unassigned int destination
//int type
//unassigned int port
//char *data
//struct node  *next link to next node
};

typedef struct Packet node; // Removes the need to constantly refer to struct

这里,
struct Packet
node
是相同的结构,没有异常情况。

为什么不使用construct:

typedef struct Packet { .... } node;
您命名了struct节点,但从type指向其中的下一个元素

struct-Packet*