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 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;

 }


                        

🖥 Program Output


 Enter a string:atnyla

 atn 

                            

📘 Explanation

None
📚 Learning Subject

Master Programming Through Practical Examples

Improve your coding logic, problem-solving skills and programming confidence by practicing real-world examples with explanations.

🎯 How to learn from this example

First understand the algorithm carefully. Then study the program line-by-line and compare it with the output. Finally, review the explanation section to strengthen your logic and programming understanding.

🔥 Practice suggestion

Rewrite the program without looking at the code. Modify values, conditions or logic and run it again. This helps improve confidence and strengthens coding skills much faster.