Retro video games delivered to your door every month!
Click above to get retro games delivered to your door ever month!
X-Hacker.org- Turbo C - <b>sprintf() write formatted data to string</b> http://www.X-Hacker.org [<<Previous Entry] [^^Up^^] [Next Entry>>] [Menu] [About The Guide]
sprintf()                Write Formatted Data to String

 #include   <stdio.h>

 int        sprintf(buffer,format-string[,argument...]);
 char       *buffer;                     Storage location for output
 char       *format-string;              Format-control string

    sprintf() formats and stores a series of characters and values in
    'buffer'.  sprintf() operates identically to printf(), with the
    exception that sprintf() "prints" to a buffer, while printf() prints
    to stdout.  With that single exception, the two functions are
    identical; see the printf() function for a complete description of
    the format-string and arguments.

  -------------------------------- Example ---------------------------------

    The following statements format and store data in 'buffer'.

         #include <stdio.h>

         char buffer[100];
         char *name = "Ali Rae";
         char age = '1';
         char s = 'F';

         main()
         {
             sprintf(buffer,"%s, %c, %c",name,age,s);
             printf("Birthdays this month: %s\n",buffer);
         }

See Also: printf() fprintf()

Online resources provided by: http://www.X-Hacker.org --- NG 2 HTML conversion by Dave Pearson