Tuesday 26 April 2016

Copy one string into another string. Remeber string is an 'char' type array.

#include <iostream>
#include <stdio.h>
using namespace std;

void strcpy(char [],char []);
int main()
{
    char array1[2000],array2[2000];
    cout<<"Enter Your Statement : "<<endl;
    gets(array1);
    cout<<"After Copying the First Statement into The Second the Second Statement Becomes : "<<endl;
    strcpy(array1,array2);
    return 0;
}
void strcpy(char array1[],char array2[])
{
    int i=0;
    while(array1[i]!='\0')
    {
        array2[i]=array1[i];
        i++;
    }
    array2[i]='\0';
    cout<<array2;
}

No comments:

Post a Comment