Search code examples
ccstring

Multiple string concatenation


I'm new to the C language and Loadrunner.

How do I do a string concatenation in C.

Pseudo code:

String second = "sec";
String fouth = "four";
System.out.println("First string" + second +"Third" + fouth);

Solution

  • If you are sure that target string can accommodate, you can use snprintf,

    #define SIZE 1024
    
    char target[ SIZE ];
    // .. ..
    snprintf( target, sizeof( target ), "%s%s%s", str1, str2, str3 );
    

    For your case,

    snprintf( target, sizeof( target ), "%s%s%s%s", "First string", second, "Third", fourth );
    

    Of course, second and fourth should be valid string (character array).