How to get value
-
I like to verify actuall value passed from char array to struct pointer buf array declaration unsigned char buf[32]; // = { 0x00, 0x04 }; value passed unsigned char 0x04; buf[0] = command; // passed 0x04 software reset transmit buffer assignment xfer[0].tx_buf = (unsigned long) buf; Now I like to use cout to print the actual value in tx_buf. From struct declaration I know "tx_buf" is a unsigned long pointer. Not sure how to access the required value this gives me the pointer as expected:
cout << "xfer[0].tx_buf " << xfer[0].tx_buf<< endl;
Once I know how to get first value I can probably figure out how to get the whole buf[32] array values.
Thanks for help
Cheers Vaclav -
I like to verify actuall value passed from char array to struct pointer buf array declaration unsigned char buf[32]; // = { 0x00, 0x04 }; value passed unsigned char 0x04; buf[0] = command; // passed 0x04 software reset transmit buffer assignment xfer[0].tx_buf = (unsigned long) buf; Now I like to use cout to print the actual value in tx_buf. From struct declaration I know "tx_buf" is a unsigned long pointer. Not sure how to access the required value this gives me the pointer as expected:
cout << "xfer[0].tx_buf " << xfer[0].tx_buf<< endl;
Once I know how to get first value I can probably figure out how to get the whole buf[32] array values.
Thanks for help
Cheers Vaclav -
You need to print each
byte
independently, after casting them toint
, since thechar
values are unprintable. Something like:cout << hex << (int)buf[0] << endl;
Use a loop to print more than one value.
Thanks, but... I know how to get buf values, what I wanted to verify is that the buf values are actually passed to the struct. I am having issues verifying that the struct has all of the necessary data. Some are "straight" values, most via pointers. BTW When I use "modifier" hex , not sure I am using correct term as always, in cout << hex << (int)buf[0] << endl;, then following usage WITHOUT such modifier will continue to print the data in hex cout << int)buf[0] << endl; Nice but it can get out of control.
-
Thanks, but... I know how to get buf values, what I wanted to verify is that the buf values are actually passed to the struct. I am having issues verifying that the struct has all of the necessary data. Some are "straight" values, most via pointers. BTW When I use "modifier" hex , not sure I am using correct term as always, in cout << hex << (int)buf[0] << endl;, then following usage WITHOUT such modifier will continue to print the data in hex cout << int)buf[0] << endl; Nice but it can get out of control.
Vaclav_ wrote:
I am having issues verifying that the struct has all of the necessary data.
You need to be specific, we cannot guess what these issues may be. And, TBH, my previous reply was also based on a bit of guesswork. See <iomanip> functions[^] for details on using the hex manipulator.
-
Vaclav_ wrote:
I am having issues verifying that the struct has all of the necessary data.
You need to be specific, we cannot guess what these issues may be. And, TBH, my previous reply was also based on a bit of guesswork. See <iomanip> functions[^] for details on using the hex manipulator.