How to combine strings in c language

htt‮.www//:sp‬lautturi.com
How to combine strings in c language

In C, you can use the strcat function to concatenate strings

// concatenate string in c
char str[80];
strcpy(str, "these ");
strcat(str, "strings ");
strcat(str, "are ");
strcat(str, "concatenated.");

Example

/*
Example: concatenate strings in C language
*/

#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#include <string.h>
#include <stdbool.h>

int main(int argc, char *argv[]) {

    char str[80];
    strcpy(str, "hello ");
    strcat(str, "lautturi ");
    strcat(str, "world. ");
    printf("%s\n", str);

    return 0;
}

output:
hello lautturi world.

Created Time:2017-08-28 22:10:10  Author:lautturi