can we store the value printed by printf() into a unsigned long variable?
I have a following array and a printf() stament,
char array[1024] = "My Message: 0x7ffff6be9600";
printf("%.14s", strstr(array, "开发者_如何学Python 0x") + 1);
The output of above printf() is 0x7ffff6be9600, can we store it into a unsigned long variable?
Look at sscanf
Since you tagged this as C++, see istringstream.
using std::istringstream;
const char source_text[] = "0x7ffff6be9600";
unsigned long value;
istringstream input(source_text);
input >> hex >> value;
Try this:
const char* numBuf = strstr(array, " 0x");
unsigned long number = 0; /* Set default value here. */
if(numBuf)
number = strtoul(numBuf + 1, 0, 0);
精彩评论