I am trying to use sscanf to to read " name value" pairs
with the value being either an unsigned 8bit or 16 bit or
32bit or 64bit numberic value.
Well a 32bit value will fit in a 64bit value, as will a 16bit
value and an 8bit value.
name1 255
name2 65535
name3 4294967295
name4 42949672954294967295
Can you please suggest how I can use sscanf to achieve this
please.
Scan for name with %s or %[, scan for an unsigned long long
with %llu.
Hi Peter
Thanks for the reply.
I should have said I am using Visual C++ 6.0.
Taking your suggestion I am able to read the values as required
( shown below ) except for the 64 bit value.
Reading the 8 bit value is OK
unsigned char val8bit
sscan ( buffer"%s %u, name, &val8bit)
Reading the 8 bit value is OK
unsigned char val8bit
sscan ( buffer"%s %u, name, &val8bit)
Reading the 16 bit value is OK
unsigned short int val16bit
sscan ( buffer"%s %d, name, &val16bit)
Reading the 32 bit value is OK
unsigned long int val32bit
sscan ( buffer"%s %lu, name, &val16bit)
Reading the 64 bit value is NOT OK
unsigned long long val64bit
sscan ( buffer"%s %llu, name, &val64bit)
I also noticed that if the value was greater than the variable storage
size, this would result in memory corrption. ie
buffer "name 65535"
unsigned char val8bit
sscan ( buffer"%s %u, name, &val8bit)
would result in writing 2 bytes starting at &val8bit when only 1 byte
was allocated. Is there a way to read values o ensure they are in the
valid range a according to the type.
Many Thanks
Pete