In c++, setw function is used to set the number of characters to be used as the field width for the next insertion operation. Is there any function in C, I mean, in standard c library, which does the same thing?
Share
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
printf ("%5d", 42);Will print 42 using 5 spaces. Read the man pages of printf to understand how character padding, overflow and other nuances work.
EDIT:
Some examples –
Gives the output
Notice that the
%2dwas too small to handle the number passed to it, yet still printed the entire value.