Anonymous asked in Computers & InternetProgramming & Design · 1 decade ago

c program for string concatenation?

C program coding

8 Answers

  • 1 decade ago
    Favorite Answer

    Try using strcat() function (Be sure to include string.h). The syntax of this function is :

    newstr = strcat(str1, str2 );

    This means the function accepts two string "str1" and "str2" as arguments and concatenates them. The concatenated string is assigned to the variable "newstr".

  • 1 decade ago

    Careful with the first parameter. There must be enough space allocated in that memory space because the second string will be appended. See the documentation link.

    Are you asking for a function or a program? If a program, then I think we don't understand the question.

  • Sonu G
    Lv 5
    1 decade ago

    String a = strcat(str1, str2 );

  • Anonymous
    1 decade ago

    this program concats 2 strings a,b using a user-defined function conc().

    a and b are passed to the function and accepted in the variables x and y . the concated word is stored in z.

    void conc(char x,char y)


    int l1=strlen(x);

    int l2=strlen(y);


    char z[l3];

    for(int i=0;i<l3;i++)







    hope this helps.

  • How do you think about the answers? You can sign in to vote the answer.
  • 1 decade ago

    If you need ready function, use strcat().

    Note that for strcat(s1, s2) s1 must have enough room to contain resulting string.

    If you need your own function, it will be as:

    s1 = realloc( s1, strlen(s1)+strlen(s2)+1);

    strcpy( s1+strlen(s1), s2 );

    That's all.

  • 1 decade ago

    already defined fn in string library.


  • 1 decade ago

    There is already a function, strcat(), which does this for you.

  • 1 decade ago



    str3 = str1 + str2;

    this is simple. note its just a partial coding.

Still have questions? Get your answers by asking now.