cancel
Showing results for 
Search instead for 
Did you mean: 

Proper way to use scanf with uint8_t

yabool2001
Associate III

What is the best way to use sscanf with uint8_t?

When I use:

  uint8_t x ;
  char* y = "23" ;
  sscanf ( y , "%hhu" , &x ) ;

I stuck at: 

void HardFault_Handler(void)

 

I found following workaround that works:

  uint16_t x1 ;
  uint8_t x2 ;
  const char* y = "23" ;
  sscanf ( y , "%hu" , &x1 ) ;
  x2 = (uint8_t) x1 ;

but it doesn't look best. So what is the right way of processing uint8_t in above case?

V/r

yabool2001

11 REPLIES 11

Likely because I'm a fossil and predominantly code to older K&R and C89 standards some of my tool chains use..

b) support only conversion specifiers defined in C89 standard. This brings us good balance between small memory footprint and full feature formatted input/output.

https://github.com/32bitmicro/newlib-nano-1.0/blob/master/newlib/README.nano#L29

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..

Thx.