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

Advertisements
z
Download Projects

Advertisements

Download WhatsApp Status Video

Buy This Ad Space Only $50 per Month, Ad Size 300X250 Contact on: [email protected] WhatsApp no. 8882538826

Google Adsense Advertisements