In this article, I will show you how you can write a C Program to concatenate two Strings using pointer. I will explain the algorithm, concepts and then help you to write C Program to concatenate two Strings using pointer.
1. Program Outline
In this program, we will take two Strings as input from the user. We will then concatenate those Strings using Pointer.
To write a C Program to concatenate two Strings using pointer. Open your favorite code editor and Let’s start writing C Program to concatenate two Strings using pointer.
2. Concepts
To write this C Program to concatenate two Strings using pointer, you need to learn the following concepts of C Programming:
- Input
- Pointer
- Increment/Decrement operator
- Output
3. Algorithm
To write this C program, follow this Algorithm:
Step 1: START Step 2: Input the String Step 3: Add Pointer Step 4: Concatenate the String Step 5: Output concatenated String Step 6: STOP
4. Program
Here’s the C Program to concatenate two Strings using pointer:
#include <stdio.h>
#define MAX_SIZE 100
int main()
{
char str1[MAX_SIZE], str2[MAX_SIZE];
char * s1 = str1;
char * s2 = str2;
// Getting String as Input
printf("Enter 1st string: ");
gets(str1);
printf("Enter 2nd string: ");
gets(str2);
while(*(++s1));
while(*(s1++) = *(s2++));
printf("Concatenated string: %s", str1);
return 0;
}
5. Output
Here’s the output of the above C Program:
