sprintf(3C)
_________________________________________________________________
sprintf function
Perform a formatted write to an internal string.
_________________________________________________________________
Calling Sequence
#include <stdio.h>
char *string;
sprintf(string, format, arg [,arg ...]);
where string is a pointer to a character array.
format is a string containing two kinds of objects:
* Ordinary ASCII characters that the function copies
directly. These include whitespace characters.
* Conversion specifications that start with %.
Each arg is a valid C variable or constant.
Description
Use the sprintf function to write to an internal string. This
function replaces the format specifications with the successive
arg, and writes the result to the string. For details of
conversion specification, see the printf function.
See the "Input/Output Functions and Macros" section of Chapter 1
for buffering information on the I/O functions and macros.
Returns
The sprintf function returns the number of characters printed.
Related Functions
See also the fprintf, printf, and sscanf functions.
Example
/* Program test for the sprintf() function */
#include <stdio.h>
DG/UX 4.00 Page 1
Licensed material--property of copyright holder(s)
sprintf(3C)
#define MAX 24
#define LIM 20
char store[MAX][LIM];
int i = 1;
main(argc, argv)
int argc;
char *argv[];
{
while (i < argc) {
sprintf(store[i], "%s\n", argv[i]);
i++;
}
while (i-- > 0)
printf("%s", store[i]);
}
A call to the program test with
x test [cities]
where the file cities contains
Albany &
Atlanta &
Baltimore &
Boston &
Chicago &
Cleveland &
Dallas &
Denver &
Memphis &
Miami
generates the output
Miami
Memphis
Denver
Dallas
Cleveland
Chicago
Boston
Baltimore
Atlanta
Albany
DG/UX 4.00 Page 2
Licensed material--property of copyright holder(s)