format for string output

format for string out put.
%w.ns
 Where w is the total number of characters in the string .Decimal point and ‘n’ are option if present than the (w-n) leading blanks are displayed before string .

(i)                 Printf( “%3s”, Rajes kumar”);

Result:
Rajes kumar
Printf(“%10s”,”Reeta”);
Result :
Reeta (w-length of string leading blanks)
(ii)printf(“%3s”,rajes kumar”);
Result:
Raj
(iii)Printf(“%8.3s”,rajesh kumar”);
Result:
- - - - -raj
(8-3=5 leading blanks)
Note – if we want to skip any   inpurt field then we specify * in the place of the field width.
Ex-
Scanf(“%d%*d%d”,&a,&b,&c);
Input:
25,30,35
 Then 25 is stored in ‘a’ ,30 is skipped and 35 is stored in the ‘b’ since no data is available for ‘c’ so it takes garbage value.
/ * program to understand this pint */
#include <stdio.h>
Main();
Int a,b,c;

 Printf ( “enter the three number:”);

Scanf(“%d %*d %d”, &a,&b&c);
Printf(“%d %d %d”,a,b,c);
}
 Input :
 25, 30, 35
Out put:
25 35 25381(garbage value)
 

Print | posted on Tuesday, November 27, 2012 5:03 PM


Advertisements at BlogUnlimited.com

Feedback

No comments posted yet.

Your comment:





 
Please add 3 and 1 and type the answer here:

Copyright © Afsana Bano

Design by Bartosz Brzezinski

Design by Phil Haack Based On A Design By Bartosz Brzezinski

Advertisements at BlogUnlimited.com