Hi all,
I'm using a piece of software called Opnet to implement a protocol and I am needing to do some programming (very much my weak point!).
I have created some code with the intention of it generating a random set of bytes and then converting the bytes to hexadecimal (string?) so it is easier to print and compare.
1 2 3 4 5 6 7 8 9
|
unsigned char byterandom[8]; // 8 byte cookie in bytes
char hexrandom[16];
RNG_Bytes(byterandom, sizeof(byterandom), NULL, 0); //creates random 8 byte cookie to be sent
CNV_HexStrFromBytes(hexrandom, sizeof(hexrandom), byterandom, sizeof(byterandom)); // converts the random bytes in byte random to a hex string stored in hexrandom
printf("random number is in hex 1 %n ", *hexrandom);
---------------------------------------------------
|
All I want to do is to be able to print the value (the hex value) rather than the memory address which seems to happen all of the time. If I use %s without the dereference, it seems to print out the value in hex form but I’m not sure if I’m bodging it this way.
From my understanding if I use the dereference operator * before the variable, instead of printing the address pointer, it prints the variable stored at the address. This doesn’t seem to work and just prints the memory address.
I'm really lost now as to what is actually stored in my variables. It should be the value e.g bytes but I get the feeling it is memory address pointer for some!
If it is any help here is the syntax for both the functions:
- long _stdcall CNV_HexStrFromBytes(char *szOutput, long nOutChars, const unsigned char *input, long nbytes);
- long _stdcall RNG_Bytes(unsigned char *lpOutput, long nOutputLen, const void *lpSeed, long nSeedLen);
Can someone please shed some light on this for me as I assume it is quite trivial but I have spend a silly amount of hours trying to bodge this!
Many thanks,
Richard