gpt4 book ai didi

c - C语言中如何获取内存地址的值

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

我正在尝试访问内存访问的值,但当我打印输出时,我不断获取地址。

char c[16];

char copyArray(unsigned char* state, unsigned char* key)
{

for (int i = 0; i < 16; i++)
{
state[i] ^= key[i];
// c[i] = state[i]; // this gave me the address
printf("%02x", state[i]);
}
printf("\n");

memcpy (c, state,16);

for (int i = 0; i < 16; ++i)
{


printf("%02d\n",c[i] );
}
printf("\n");

}

该函数在另一个函数中执行了 10 次。我想要实现的是存储上次执行的值而不是地址

最佳答案

谢谢大家!

现在已经解决了。我使 c 数组无符号,这解决了问题

unsigned char c[16];

char copyArray(unsigned char* state, unsigned char* key)
{

for (int i = 0; i < 16; i++)
{
state[i] ^= key[i];

printf("%02x", state[i]);
}

printf("\n");

memcpy (c, state,16);

for (int i = 0; i < 16; ++i)
{
printf("%02x\n",c[i] );
}
printf("\n");

}

关于c - C语言中如何获取内存地址的值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53144638/

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