C Program to Copy First String into Second String

Advertisements

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 Advertisment

Buy This Ad Space @$20 per Month, Ad Size 600X200 Contact on: hitesh.xc@gmail.com or 9999595223

Magenet is best Adsense Alternative here we earn $2 for single link, Here we get links ads. Magenet

For Projects 9999595223

Google Advertisements


Buy Websites 9999595223

Buy College Projects with Documentation Contact on whatsapp 9999595223. Contact on: hitesh.xc@gmail.com or 9999595223 Try this Keyword C++ Programs

Advertisements