Pages

Sunday 20 May 2012

program to print a String and a another String and connect it


90./*Write a program to print a String and a another String and connect it*/
#include<stdio.h>
#include<conio.h>
main()
{
            char string1[20],string2[20],string3[40];
            int i,j,k;
            int len=0;
            clrscr();
            printf("Enter a string:");
            gets(string1);
            printf("Enter Another string:");
            gets(string2);
            for(i=0;string1[i]!='\0';i++)
            {
             string3[i]=string1[i];
             len++;
            }
            for(j=len,k=0;string2[k]!='\0';j++,k++)
             {
              string3[j]=string2[k];
             }
            string3[j]='\0';
            printf("The concatenated string is:%s",string3);
            getch();
}

OUTPUT
            Enter a string:MAHESH
            Enter Another string: SOLANKI
            The concatenated string is : MAHESHSOLANKI

No comments:

Post a Comment