• C

How to align numbers in C using the %d

I am trying to align the numbers to look like the following:  Could you please help

Data Type   Size in Bytes   Size in Bits
int                         4                       32
double                 8                       64
short int              2                        16
long int                4                        32
char                     1                           8
float                     4                        32
This is the code I am using
void displayToScreen(void)
      // Display headings to screen
   printf("\n                 SIZE OF REPORT ");
   printf("\n\n Data Type   Size in Bytes   Size in Bits");
   // Display detail lines
   printf("\n int %16d%15d",sizeof(int), CHAR_BIT * sizeof(int));
   printf("\n double %16d%15d", sizeof(double), CHAR_BIT * sizeof(double));
   printf("\n short int %16d%15d", sizeof(short int), CHAR_BIT * sizeof(short int));
   printf("\n long int %16d%15d", sizeof(long int), CHAR_BIT * sizeof(long int));
   printf("\n char %16d%15d", sizeof(char), CHAR_BIT * sizeof(char));
   printf("\n float %16d%15d", sizeof(float), CHAR_BIT * sizeof(float));
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

   printf("\n int       %16d%15d",sizeof(int), CHAR_BIT * sizeof(int));
   printf("\n double    %16d%15d", sizeof(double), CHAR_BIT * sizeof(double));
   printf("\n short int %16d%15d", sizeof(short int), CHAR_BIT * sizeof(short int));
   printf("\n long int  %16d%15d", sizeof(long int), CHAR_BIT * sizeof(long int));
   printf("\n char      %16d%15d", sizeof(char), CHAR_BIT * sizeof(char));
   printf("\n float     %16d%15d", sizeof(float), CHAR_BIT * sizeof(float));

Open in new window

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
cookiejarAuthor Commented:
Thank you!
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today

From novice to tech pro — start learning today.