Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>In C, "strings" are just plain <code>char</code> arrays. Therefore, you can't directly concatenate them with other "strings". </p> <p>You can use the <code>strcat</code> function, which appends the string pointed to by <code>src</code> to the end of the string pointed to by <code>dest</code>:</p> <pre><code>char *strcat(char *dest, const char *src); </code></pre> <p>Here is an <a href="http://www.cplusplus.com/reference/clibrary/cstring/strcat.html" rel="noreferrer">example from cplusplus.com</a>:</p> <pre><code>char str[80]; strcpy(str, "these "); strcat(str, "strings "); strcat(str, "are "); strcat(str, "concatenated."); </code></pre> <p>For the first parameter, you need to provide the destination buffer itself. The destination buffer must be a char array buffer. E.g.: <code>char buffer[1024];</code></p> <p><strong>Make sure</strong> that the first parameter has enough space to store what you're trying to copy into it. If available to you, it is safer to use functions like: <code>strcpy_s</code> and <code>strcat_s</code> where you explicitly have to specify the size of the destination buffer. </p> <p><em>Note</em>: A string literal cannot be used as a buffer, since it is a constant. Thus, you always have to allocate a char array for the buffer.</p> <p>The return value of <code>strcat</code> can simply be ignored, it merely returns the same pointer as was passed in as the first argument. It is there for convenience, and allows you to chain the calls into one line of code:</p> <pre><code>strcat(strcat(str, foo), bar); </code></pre> <p>So your problem could be solved as follows:</p> <pre><code>char *foo = "foo"; char *bar = "bar"; char str[80]; strcpy(str, "TEXT "); strcat(str, foo); strcat(str, bar); </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload