C Programming Tutorial

Advertisements

Write a program to concatenate two strings in C



       #include<stdio.h>
       #include<conio.h>

       void main()
       {

              char str1[50],str2[50],str3[50];
              int i,k=0;
              clrscr();

              printf("\nEnter 1st string : ");
              gets(str1);
              
              printf("\nEnter 2nd string : ");
              gets(str2);

              for(i=0;str1[i];i++)
                     str3[k++] = str1[i];

              for(i=0;str2[i];i++)
                     str3[k++] = str2[i];

              str3[k++] = '\0';
              
              printf("\nThird string : %s",str3);

              getch();
    }

   Output : 

              Enter 1st string : Hello sumit,
              Enter 2nd string : how r u.
              Third string : Hello sumit, how r u




Advertisement