Monday, 23 November 2015

C++ Program To Copy One String To Another String Without Library Function

Problem :- Write a c++ program to copy one string to another string without library function .

Logic :- For this problem you can use two method one method is Using Library Function and second is Without Using Library Function .

Using Library Function :-
strcpy :- You can use strcpy for copy string syntax is given below 

Syntax :- strcpy (destination , source)
it will copy from source and paste into destination 

Without Using Library Function :-
you can use loop and copy character by character string 

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


Solution :-

#include<iostream>
using namespace std;

int main()
{
  //By-Ghanendra Yadav 
  char s1[100], s2[100], i;
  
  cout<<"Enter The First String s1: ";
  cin>>s1;
  
  for(i=0; s1[i]!='\0'; ++i)
  {
    s2[i]=s1[i];
  }
 
s2[i]='\0';
  cout<<"String Two Is s2: "<<s2;
return 0;
}

Output:-

C++ Program To Copy One String To Another String Without Library Function

No comments:
Write comments

Recommended Posts × +