简体   繁体   English

如何在C中获取内存地址的值

[英]How to get the value of memory address in C

I am trying to access the value of a memory access, but I keep getting the address, when I print the output.我正在尝试访问内存访问的值,但是在打印输出时我一直在获取地址。

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");

}

This function is executed 10 times in another function.该函数在另一个函数中执行 10 次。 What I am trying to achieve is to store the value of the last execution instead of the address我想要实现的是存储上次执行的值而不是地址

Thanks guys!谢谢你们!

It is solved now.现在已经解决了。 I made the c array unsigned, and that solved the problem我使 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");

}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM