In: Computer Science
//Code starts here
#include <stdio.h>
void concatenate_string(char *a, char *b) //Arguments are pointers
to strings a and b
{
while(*a) //Loop to move "a" to end of string
a++;
while(*b) //Now we will copy 'b' characters into 'a' until end of
b
{
*a = *b;
a++;
b++;
}
//Note that pointer a will point to concatenated string
*a = '\0'; // '/0' to terminate string
}
int main()
{
char a[100], b[100]; //Defining the two strings
printf("Enter source string\n");
gets(a); //Storing a through user input
printf("Enter string to concatenate\n");
gets(b);
//This function will concatenate a and b and result will be in
a
concatenate_string(a, b);
//Printing a
printf("String after concatenation: %s", a);
return 0;
}
//Code ends here