gpt4 book ai didi

c - 在 C 中复制无符号整数值时出现段错误

转载 作者:太空宇宙 更新时间:2023-11-04 10:04:17 24 4
gpt4 key购买 nike

<分区>

您好,我尝试为 SNMP Get 函数复制 Counter64 类型,但出现段错误。现在我写了一个普通的 C 函数并在 LINUX 中使用 gcc 编译我得到了这个错误

Segmentation fault (core dumped)

我在 UBUNTU 64 位 PC 上运行。请帮助解决此错误。我的代码是

#include <stdio.h>
#include <string.h>

typedef struct SNMP_COUNTER64_TYPE {
unsigned int msn;
unsigned int lsn;
} tSNMP_COUNTER64_TYPE;

int main (void)
{
unsigned int a = 50;
unsigned int b = 20;

tSNMP_COUNTER64_TYPE *pu8RetVal;
memset(pu8RetVal, 0, sizeof(tSNMP_COUNTER64_TYPE));

pu8RetVal->msn = a;
pu8RetVal->lsn = b;

printf("\n\t%d.%d\n", pu8RetVal->msn, pu8RetVal->lsn);
}

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