Monday, June 18, 2012

To concatenate two strings


/* Program to concatenate two strings */

#include<stdio.h>

#include<conio.h>

void main()

{

  char str1[20],str2[20];

  int i=0,j=0;

  clrscr();

  printf("Enter first string:");

  gets(str1);

  printf("Enter second string:");

  gets(str2);

  while(str1[i]!='\0')

    i++;

  while(str2[j]!='\0')

  {

    str1[i]=str2[j];

    j++;

    i++;

  }

  str1[i]='\0';

  printf("\nConcatenated String:%s",str1);

  getch();

}

 

OUTPUT

Enter first string:good

Enter second string:morning

 

Concatenated String:goodmorning

 

No comments:

Post a Comment

Note: Only a member of this blog may post a comment.