Archive

Posts Tagged ‘printf’

Print __int64 values using printf

Print substrings using printf

We can use printf and it’s family of functions to print substrings, real nice. Have a look

char* pStars = "***************";
int nStarLength = strlen( pStars );

while( nStarLength )
{
  --nStarLength;
  printf( "%.*s\n", nStarLength, pStars );
}

‘*’ will be replaced by value of nStarLength. Number after ‘.’ specifies length of substring from pStars to be printed.

The output will produce this effect

***********
**********
*********
********
*******
******
*****
****
***
**
*
%d bloggers like this: