Monday, March 27, 2017

write a program that will take 2 string from user and copy the string into first string

#include<stdio.h>
main()
{
    int i;
    char str1[100],str2[100];
    printf("Enter first string   ");
    gets(str1);/// str1 = "We"



    printf("Enter 2nd string   ");
    gets(str2);/// str1 = "are"
    /**
    //built in  code
      strcpy(str1  , str2  );
    */

    /// briefly code

    for(i=0;str2[i]!=NULL;i++)///str2 = "are"  str1[]="are"
    {
        str1[i]= str2[i];
    }
    str1[i] = NULL;

    printf("Successfully copied  ");
    puts(str1);///are

}

No comments:

Post a Comment