English Deutsch Français Italiano Español Português 繁體中文 Bahasa Indonesia Tiếng Việt ภาษาไทย
All categories

C program coding

2006-12-22 00:54:31 · 8 answers · asked by Anonymous in Computers & Internet Programming & Design

8 answers

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".

2006-12-22 01:11:18 · answer #1 · answered by Bhargav 3 · 0 0

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.

2006-12-22 01:39:27 · answer #2 · answered by JK 1 · 0 0

String a = strcat(str1, str2 );

2006-12-22 02:31:46 · answer #3 · answered by Sonu G 5 · 0 0

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);
l3=l1+l2;
char z[l3];
for(int i=0;i {
z[i]=x[i];
z[i+l1]=y[i];
}
cout.write(z);
}
hope this helps.

2006-12-22 04:25:20 · answer #4 · answered by Anonymous · 0 0

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.

2006-12-22 01:41:08 · answer #5 · answered by alakit013 5 · 0 0

already defined fn in string library.
strcat()

2006-12-22 02:30:06 · answer #6 · answered by na k 1 · 0 0

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

2006-12-22 01:03:16 · answer #7 · answered by Klaudelu 2 · 0 0

str1="string1"
str2="string2"
str3 = str1 + str2;
this is simple. note its just a partial coding.

2006-12-22 04:23:23 · answer #8 · answered by Sudha P 2 · 0 1

fedest.com, questions and answers