HELPLIB.HLB  —  CRTL  sprintf
    Performs formatted output to a string in memory.

    Format

      #include  <stdio.h>

      int sprintf  (char *str, const char *format_spec, . . . );

1  –  Arguments

 str

    The address of the string that will receive the formatted output.
    It is assumed that this string is large enough to hold the
    output.

 format_spec

    A pointer to a character string that contains the format
    specification.

  . . .

    Optional expressions whose resultant types correspond to
    conversion specifications given in the format specification.

    If no conversion specifications are given, you may omit the
    output sources. Otherwise, the function calls must have at least
    as many output sources as there are conversion specifications,
    and the conversion specifications must match the types of the
    output sources.

    Conversion specifications are matched to output sources in left-
    to-right order. Excess output pointers, if any, are ignored.

2  –  Description

    The sprintf function places output followed by the null character
    (\0) in consecutive bytes starting at *str. The user must ensure
    that enough space is available.

    Consider the following example of a conversion specification:

    #include <stdio.h>

    main()
    {
       int  temp = 4, temp2 = 17;
       char s[80];

       sprintf(s, "The answers are %d, and %d.", temp, temp2);
    }

    In this example, character string s has the following contents:

    The answers are 4, and 17.

3  –  Return Values

    x                  The number of characters placed in the
                       output string, not including the final null
                       character.
    Negative value     Indicates an output error occurred. The
                       function sets errno. For a list of errno
                       values set by this function, see fprintf.
Close Help