RAD Studio
ContentsIndex
PreviousUpNext
printf, wprintf

Header File 

stdio.h  

Category 

Console I/O Routines 

Prototype 

int printf(const char *format[, argument, ...]); 

int wprintf(const wchar_t *format[, argument, ...]); 

Description 

Writes formatted output to stdout. 

The printf function:

  • Accepts a series of arguments
  • Applies to each argument a format specifier contained in the format string *format
  • Outputs the formatted data (to the screen, a stream, stdout, or a string)
There must be enough arguments for the format. If there are not, the results will be unpredictable and likely disastrous. Excess arguments (more than required by the format) are merely ignored.
Note: For Win32 GUI applications, stdout must be redirected.
Return Value 

On success, printf returns the number of bytes output.  

On error, printf returns EOF. 

More About printf 

Example  

#include <stdio.h>
#include <string.h>
#define I 555
#define R 5.5
int main(void)
{
   int i,j,k,l;
   char buf[7];
   char *prefix = buf;
   char tp[20];
   printf("prefix  6d      6o      8x        10.2e        "
          "10.2f\n");
   strcpy(prefix,"%");
   for (i = 0; i < 2; i++)
   {
      for (j = 0; j < 2; j++)
         for (k = 0; k < 2; k++)
            for (l = 0; l < 2; l++)
            {
               if (i==0)  strcat(prefix,"-");
               if (j==0)  strcat(prefix,"+");
               if (k==0)  strcat(prefix,"#");
               if (l==0)  strcat(prefix,"0");
               printf("%5s |",prefix);
               strcpy(tp,prefix);
               strcat(tp,"6d |");
               printf(tp,I);
               strcpy(tp,"");
               strcpy(tp,prefix);
               strcat(tp,"6o |");
               printf(tp,I);
               strcpy(tp,"");
               strcpy(tp,prefix);
               strcat(tp,"8x |");
               printf(tp,I);
               strcpy(tp,"");
               strcpy(tp,prefix);
               strcat(tp,"10.2e |");
               printf(tp,R);
               strcpy(tp,prefix);
               strcat(tp,"10.2f |");
               printf(tp,R);
               printf("  \n");
               strcpy(prefix,"%");
            }
       }
   return 0;
}

Portability

 
POSIX 
Win32 
ANSI C 
ANSI C++ 
printf 
_wprintf 
 
 
 
Copyright(C) 2008 CodeGear(TM). All Rights Reserved.
What do you think about this topic? Send feedback!