string format help

T

Tagore

What is difference between following 2 statements:
1) printf("%.5s","ABCDEFGHIJKL");
2) printf("%5s","ABCDEFGHIJKL");

basically I want to know that what does "." represent in format
string?.....I am clear about what it would mean if used like %.
5f ...i.e it will print 5 places after decimal...but what does it
represent in string..
 
L

lawrence.jones

Tagore said:
What is difference between following 2 statements:
1) printf("%.5s","ABCDEFGHIJKL");
2) printf("%5s","ABCDEFGHIJKL");

basically I want to know that what does "." represent in format
string?.....I am clear about what it would mean if used like %.
5f ...i.e it will print 5 places after decimal...but what does it
represent in string..

The "." separates the field width and the precision. The field width is
the minimum number of characters to appear -- shorter results will be
padded to that length. The precision means different things for
different conversions. As you know, for %f, it's the number of digits
after the decimal point. For %s, it's the maximum number of characters
to appear -- longer strings will be truncated.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,997
Messages
2,570,240
Members
46,830
Latest member
HeleneMull

Latest Threads

Top