C program strcat string
string add using strcat in c program :
In the C Programming Language, the strcat function appends a copy of the string pointed to by s2 to the end of the string pointed to by s1. It returns a pointer to s1 where the resulting concatenated string resides.
Example :
Input :
str: atikur
str2: rtahman
Output : atikur rahman
program code :
#include<stdio.h>
#include<string.h>
int main()
{
char str[100]="atikur ";
char str2[100]="rahman";
strcat(str, str2);
printf(" %s ",str);
return 0;
}
Output :
without (strcat) string function in program :
Example :
Input :
str: atikur
str2: rtahman
Output : atikur rahman
program code :
#include<stdio.h>
int main()
{
int i,j;
char st[100]="atkur ";
char st2[100]="rahman";
for(i=0;st[i]!='\0'; i++);
for(j=0;st2[j]!='\0'; j++)
{
st[i+j]=st2[j];
}
printf("%s",st);
return 0;
}
output :

No comments