Home / Programs / Write a program that demonstrates the use of width and number of character specifier with %s conversion specifier in printf( ) when used with strings.
Programming Example

Write a program that demonstrates the use of width and number of character specifier with %s conversion specifier in printf( ) when used with strings.

👁 840 Views
💻 Practical Program
📘 Step by Step Learning
Write a program that demonstrates the use of width and number of character specifier with %s conversion specifier in printf( ) when used with strings.

Program Code

#include <stdio.h>

int main()
{
  char str[50];

  printf("\n Enter a string:");
  scanf("%s",str);

  printf("\n %*.*s\n",2,3,str);

  return 0;

 }

Output


 Enter a string:atnyla

 atn 

Explanation

None

How to learn from this program

First read the algorithm, then study the program code line by line. After that, compare the code with the output and finally go through the explanation. This approach helps learners understand both the logic and the implementation properly.