C Program to Copy First String into Second String


Prev Tutorial Next Tutorial

Copy First String into Second String Program in C

C Program to Copy First String into Second String

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

void main()
{
  char s1[100], s2[100], i;
  clrscr();
  printf("Enter string s1: ");
  scanf("%s",s1);
  for(i=0; s1[i]!='\0'; ++i)
  {
    s2[i]=s1[i];
  }
  s2[i]='\0';
  printf("String s2: %s",s2);
getch();
}

Output

Enter string s1: hitesh
String s2: hitesh 

Explanation of Code

Code

for(i=0; s1[i]!='\0'; ++i)
 {
  s2[i]=s1[i];
 }

In the above code first we check string first is not null and after that we initialize one by one elements of first string into second string.


Prev Tutorial Next Tutorial

Google Advertisements
Download Projects

Google Adsense Advertisements

Buy 3 Year Old Domain, Tutorialday.com, SeosmoTools.com @$200

Buy This Ad Space @$50 per Month, Ad Size 300X250 Contact on: hitesh.xc@gmail.com WhatsApp no. 8882538826

Yahoo Advertisements