Thursday, 14 February 2013

Formatted Output


—printf() is used for printing results
—
—printf(“control string”, arg1,arg2…..);
—
—Control String specifies
—characters that will be printed on screen
—Format Specifications
—Escape sequence characters

Examples
—printf(“Programming in C”);
—printf(“\n”);
—printf(“%d”,x);
—printf(“x=%d\n”,x);
—printf(“The value of a is %d”,a);
—
—printf does not supply new line automatically. Thus ‘\n’ is used
Integer Examples





Real Examples
—Syntax: %w.pf
—w indicates the number of digits used for display
—p indicates the number of digits to be displayed after decimal
—Let y=98.7654;






String Examples
—Syntax: %w.ps
—w specifies width of field
—p specifies only first p characters of string are displayed
—
—Ex:
—char a[20]=“Hello World”;
—printf(“%s”,a);

No comments:

Post a Comment

String functions

Read This: strncpy() strncat() strstr () strlen() — Predefined function defined in string.h . — — Returns the len...