c - 将结构传递给C中的函数时损坏
问题描述
所以我有这个结构,我已经将front的值设置为0,但是当它进入一个函数时,这个值会跳转到一个非常高且看似随机的数字,例如“1868038144”。我不知道为什么会发生这种情况以及如何解决它。这是结构的结构:
#define MQA 3 //Defines the maximum amount of queues
#define MQS 5 //Defines the maximum queue size of each message queue (amount of messages)
#define MLN 200 //Defines the maximum size of a message
typedef struct MessQ{//A single message queue
char messages[MQS][MLN];
char id[50];
}MessQ_t;
typedef struct MsgQs{//An array of message queues
MessQ_t * queue;
int front; //helps define the next queue to be added
int back;
}MsgQs_t;
这是我将其传递给的函数:
//creates a new queue and which is assigned an identifier passed as argument
void createQ(MsgQs_t *mq, char ident[50]){
printf("This front: %d\n ",mq->front);
if(mq->front<=MQA){
printf("THIS IS THE FRONT %d\n",mq->front);
strcpy( mq->queue[mq->front].id, "yes");
mq->front++;//Increments this to keep track of where the next queue should be put
printf("THIS IS THE FRONT %d\n",mq->front);
}
else{printf("Out of room \n");}
}
这是我用来主要引用它的代码:
printf("THIS IS THE FRONT %d\n",msq.front);
char ide[50]="ThisIsTheId";
createQ(&msq, ide);
解决方案
推荐阅读
- android - 无需调用外部服务器即可获取 Internet ip
- amazon-web-services - 使用 Terraform 向 DynamoDB 添加非键属性。
- c# - 'FROM' 关键字附近的语法不正确。C#
- android - 如何使用 Zebra_RFIDAPI3_SDK_2.0.0.2 在 RFID Scan for Zebra 8500 中读取电池属性?
- python - Pandas - 有条件地存储输出
- css - CSS 在 Bootstrap 4.1 中获得圆形轮播指示器?
- image-processing - 如何运行图像魔法的转换命令
- javascript - 如何在mysql语句中插入动态参数?
- ckeditor - ckeditor 删除内联样式和 iframe
- laravel - 未定义的方法 Illuminate\Database\Query\Builder::setPath()