Concatenate the given two strings using pointers
Program:
#include<stdio.h>
#include<conio.h>
void main()
{
char *str1, *str2;
int i, j;
clrscr();
printf("Enter the first string : ");
scanf("%s", str1);
printf("\nEnter the second string : ");
scanf("%s", str2);
for(i = 0; *str1 != '\0'; i++, str1++);
for(j = 0; *str2 != '\0'; j++, str1++, str2++)
*str1 = *str2;
*str1 = '\0';
str1 = str1 - i - j;
printf("\nThe concatenated string is : %s", str1);
getch();
}
Output:
Enter the first string : hello
Enter the second string : world
The concatenated string is : helloworld
-
UpdatedDec 31, 2019
-
Views11,041
You May Like
Program to maintain employee details using structures
Program to maintain student details using structures
Check whether the person is eligible to vote or not
Print the numbers that are divisible by a given no.
Program to generate magic square
To sort the given numbers in ascending & descending order