Created: 2023-08-16 16:08
Status: #concept
Subject: Programming
Tags: C Strings stdio.h
Conversion Specifier
They help us specify how the compiler will transform Expressions into Strings, notably their:
m
Minimum Field Width, the characters the string occupies.p
Precision of the decimal pointsX
C Data Type (main conversion specifier that you'll use)
%m.pX
- here
m
is the Minimum Field Width. .p
is the Precision of the decimal points.X
is the Conversion Specifier to be printed liked
,f
,c
.- we may also add a
-
beforem
to make the minimum field width left-justified.
printf("%10.2f\n", 3.142f);
printf("%10.2f\n", 12.69f);
/*** OUTPUT ***/
------3.14
-----12.69
printf("%-10.2f\n", 3.142f);
printf("%-10.2f\n", 12.69f);
/*** OUTPUT ***/
3.14------
12.69-----
References
- C Programming, A Modern Approach, 2nd Edition, Chapter 3.