Share this page

# strncat

String Manipulation Functions

Concatenates n characters from one string to another.

    char *strncat( char *to_string, const char *from_string, size_t n );

to_string | The string to which n characters are concatenated.
from_string | The string from which n characters are concatenated.
n | The number of characters to be concatenated.

## Return Values

Returns a pointer to the concatenated string (null-terminated).

## Example

The following example of strncat creates a filename that conforms to the 8.3 DOS file name format i.e., the name must be no more than 8 characters and the file suffix must be 3 characters long.

The file name created is in the form [Vuser_id]_apptest.log. When running the example in VuGen, the Vuser ID as returned by lr_whoami is -1, two characters in length. strncat appends the string "_apptest" to this, but makes sure that it appends no more than the amount of characters needed to make up 8 characters only. The final name is "-1_appte.log".

Copy code

        #include <string.h>
        int id, length, chars_remaining;
    // 8 characters + full stop + 3 characters + null
        char filename[13];
        lr_whoami (&id, NULL, NULL);
        sprintf (filename, "%d_", id);
        lr_output_message ("filename so far=%s", filename);
        length = strlen(filename);
        lr_output_message ("length so far=%d", length);
        chars_remaining = 8 - length;
        lr_output_message ("chars remaining=%d", chars_remaining);
        strncat(filename, "apptest", chars_remaining);
        lr_output_message ("filename without suffix=%s", filename);
        strcat(filename, ".log");
        lr_output_message ("final filename=%s", filename);

    Example: Output:
    Action.c(8): filename so far=-1_
    Action.c(10): length so far=3
    Action.c(12): chars remaining=5
    Action.c(14): filename without suffix=-1_appte
    Action.c(16): final filename=-1_appte.log

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: