gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-11-30 17:52:25 25 4
gpt4 key购买 nike

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

/*********************************************************
* 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 Packet 而没有定义它。

struct node 的定义中,您使用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 Packetnode是相同的结构,没有异常。

关于c - 链接列表,路径大小不完整类型的无效应用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16212724/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com