Printf() Functions and its different Types with example

  • printf   sends formatted output to stdin 
  • cprintf  sends formatted output to the text window on the screen
  • fprintf  sends formatted output to a stream
  • sprintf  sends formatted output to a string
  • vfprintf sends formatted output to a stream, using an argument list
  • vprintf  sends formatted output to stdin, using an argument list
  • vsprintf sends formatted output to a string, using an argument list
Declaration:
  • int cprintf (              const char *format [, argument, ...]);
  • int fprintf (FILE *stream, const char *format [, argument, ...]);
  • int printf  (              const char *format [, argument, ...]);
  • int sprintf (char *buffer, const char *format [, argument, ...]);
  • int vfprintf(FILE *stream, const char *format, va_list arglist);
  • int vprintf (              const char *format, va_list arglist);
  • int vsprintf(char *buffer, const char *format, va_list arglist);
Note:
  • All these functions are declared in STDIO.H, except cprintf, which is declared in CONIO.H.
Functions:
  • Accept a series of arguments
  • Apply to each argument a format specifier contained in the format string *format
  • Output the formatted data (to the screen,a stream, stdin, or a string)
These functions apply 
  1. the first format specifier to the first argument, 
  2. thesecond specifier to the second argument, 
  3. the third to the third, etc., to the end of the format.
 Return Value:  

 On success,
  • the ...printf functions return the number of bytes output
  • cprintf returns the number of characters output
  •  sprintf does not include the terminating null byte in the count
On error,
  •  these functions return EOF 
Example Program:
#include<stdio.h>
#include<conio.h>
void main()
{
int l;
clrscr();
printf("Enter the value:");
scanf("%d",&l);
printf("The Stored Value: %d",l);
getch();
}
Sample Output:

 

No comments:

Post a Comment

Let Us hear Your thoughts about this Post.. Its Our Pleasure to get your feedback..

Programs and Solutions