> One question:
>
> printf("Num: %X.Ys", num);
>
> Here I want X.Y to be dynamic, i.e. I want it to change it according to
> requirement.  Can I do it?
> The problem is I have to print a table.  Depending on the lenth of a string
> I have to change the spaces.
>
> If I give printf("Num: %9.8s", num); then it uses 9 places to print 8 chars.
> My problem is that it may vary.
>
>
> With Regards
> Pruthvi PN,
> ------------------------------------------------------------
> Software Engineer, India Software Labs,
> IBM Global Services India Ltd.,
> 7th floor, Golden Enclave, Airport road,
> Bangalore


In X.Y above, X specifies minimum width and Y specifies the precision.
Instead of giving absolute numbers, you can use an asterisk, *.

    The field width may also be specified by an asterisk, *, in which
case an argument of type int is consumed and specifies the minimum
width field.  The result of specifying  a negative width is
undefined.

    The precision may also be specified by an asterisk following
the period, in which case an argument of type int is consumed
and specifies the precision.  If both the fields width and precision
are specified with asterisks, then the field width argument preceds
the precision argument.

For example:


#include <stdio.h>
#include <string.h>

/* You calculate this according to your requirement */
#define SOME_VALUE 5

int
main ( void )
{
    char calvin[] = "Calvin and Hobbes";
    char animal[] = "Animal Crackers";

    int width = strlen ( calvin ) + SOME_VALUE;
    int prec = strlen ( calvin )  + SOME_VALUE;

    printf ( "%*.*s\n", width, prec, calvin );
    return 0;
}