Share this page

# sprintf

Input-Output Functions

Writes formatted output to a string.

    int sprintf( char *string_buffer, const char *format_string[, args]);

string | The target string buffer to which you write the data.
format_string | One or more formatting characters.
args | One or more optional print arguments.

For sprintf details, refer to your C language documentation.

The target string_buffer must be large enough to contain the result of the format_string and args. Buffer overflow if the result string is larger than the buffer may cause erratic behavior in the script.

## Return Values

If successful, the function returns the total number of characters printed. Upon error, it returns a negative number.

## Example

The following example uses sprintf to write the name of a file to a string buffer, filename. This name is made up of the word "log", an underscore, the value of i,and the file suffix.

Copy code

        int index = 56;
        char filename[64], * suffix = "txt";
        sprintf(filename, "log_%d.%s", index, suffix);
        lr_output_message ("The new file name is %s", filename);

    Example: Output:
    Action.c(9): The new file name is log_56.txt

Tips to improve your search results... VuGen Function Reference Version 26.1-26.3 Function Reference 26.1-26.3 All View Local Help Center View Online Help Center Version: