C Program to Copy First String into Second String
Advertisements
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.
Google Advertisment