Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

C - printf - remove leading zeroes

Tags:

c

printf

When I use printf like this:

printf("%.*ju ", size_length, (uintmax_t) thing->fts_statp->st_size);

It adds leading zeroes to make thing->fts_statp->st_size the length size_length (which is somewhat acceptable because its the right size, but visually unappealing). Is there a way to print size information with printf that doesn't do this?

EDIT for more information:

Currently it prints like this:

00012

00234

51234

01203

00001

I'd like it to print

   12

  234

51234

 1203

    1
like image 348
user3475234 Avatar asked Apr 22 '26 08:04

user3475234


1 Answers

If you just want space padding:

printf("% *ju ", size_length, (uintmax_t) thing->fts_statp->st_size);
like image 197
Michael Avatar answered Apr 24 '26 21:04

Michael



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!