1

I have a main.c code (cannot be changed) :

int main() {
  uint8_t *param ;
  param = func(key) ; 
}

Key is an array of 16 elements and func is declared in a stud.c that is linked to main by stud.h. the func() is declared as follows

void *func(void *key){//some code}

Now how can i print param ? i have tried multiple options with printf . Is there any suggestion plZ ? I need the param as an array of 16 elements in hex format also. I cannot change anything in main.c (i cannot change any type!!!)

for(int j = 0; j < 16; j++) {
    printf("%02X ", param[j]);
}
printf("\n");
gsamaras
  • 71,951
  • 46
  • 188
  • 305
Ceasar Dll
  • 29
  • 3
  • 1
    To be sure you're correctly printing stuff defined in `stdint.h`, try `printf("%02"PRIX8" ", param[j]);` adding `#include `. – Giovanni Cerretani Nov 30 '18 at 08:32
  • Possible duplicate of [How to print uint32\_t and uint16\_t variables value?](https://stackoverflow.com/questions/12120426/how-to-print-uint32-t-and-uint16-t-variables-value) – Giovanni Cerretani Nov 30 '18 at 08:41

1 Answers1

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

since your array is of type uint8_t.

Do not forget to #include <inttypes.h>.

Read more in Good introduction to <inttypes.h>, where other naming conventions are explained, e.g. PRIx8 if you want to print the hexadecimal value.

gsamaras
  • 71,951
  • 46
  • 188
  • 305
  • 1
    Somewhere else in your code @CeasarDll. I think I answered your question. If I were you, I would accept this answer (since it's correct), and try debugging my program, by using a debugger (like `gdb` for example). Then, if I still needed help, I would create an [MCVE](https://stackoverflow.com/help/mcve), and post a *new* question. – gsamaras Nov 30 '18 at 09:14