Contact Learn C
Copy Program Share Program

Program 190:To Concatenate two strings using Pointers

Program 190:
 
 #include<stdio.h>
main()
{
  char s1[25],s2[25],*t1,*t2;
  int len1=0,len2=0,i;
  printf("Enter a string 1\n");
  scanf("%s",&s1);
  printf("Enter a string 2\n");
  scanf("%s",&s2);
  t1=s1;//copying base address of string
  t2=s2;
  while(*t1!='\0')
  {
   t1++;
   len1++;
  }
 //copying second string to first
  while(*t2!='\0')
  {
   *t1=*t2;
   t1++;
   t2++;
   len2++;
  }
  *t1='\0';
  i=0;
  //taking total string to initial base address 
  while(i<len1+len2)
  {
   i++;
   t1--;
  }
  
    printf("Concatenated String is ");
    
    while(*t1!='\0')
    {
     printf("%c",*t1);
     t1++;
    }

printf("\n");
}

Explanation:

//Coming Soon...

Output:


To Concatenate two strings using Pointers







 

Download App and Learn when ever you want

Get it on PlayStore
Get it on Amazon App Store
Get it on Aptoide