Blog Moved

This website completely moved to new domain. For latest content, visit www.programmingposts.com

Search This Blog

6 Oct 2012

C PROGRAM TO CONCATENATE TWO GIVEN STRINGS


/*** C PROGRAM TO CONCATENATE TWO GIVEN STRINGS ***/
#include<stdio.h>
#include<conio.h>
#define MAX 100 
main()
{
  int i,j,k;
  char str1[MAX],str2[MAX],strnew[2*MAX];
  clrscr();
  printf("\n****PROGRAM TO CONCATENATE STRINGS****\n");
  printf("\nEnter the String1:");
  scanf("%s",&str1);
  //gets(str1); //for allowing spaces in a string u can use 
                  gets() instead of scanf() 
  printf("\nEnter the String2:");
  scanf("%s",&str2);
  //gets(str2);//for allowing spaces in a string u can use 
                  gets() instead of scanf()
  printf("\n The concatinated string is:\n");

  for(i=0;str1[i]!='\0';i++)
  {
    strnew[i]=str1[i];   //stroing string 1 in another string
    k=i;
  }

   for(j=0;str2[j]!='\0';j++)
   {
     strnew[++k]=str2[j]; //concatinating string 2 to string 1
   }
   strnew[++k]='\0';   // ending the concated string
   printf("\n>>  %s <<",strnew);
    getch();

}


Output:

1 comment:

  1. thank you for sharing useful article
    web programming tutorial
    welookups

    ReplyDelete