Search This Blog

Thursday, 14 June 2018

CS201 Introduction to Programming - Function that copy a array into other array

//Copy a array of string into another array of string

#include <iostream>  //for input and output

using namespace std;

void copystr(char *destination, const char *source);

main()   //Main function begins
{
char str1[30]="This is the test string";
char str2[30];

cout << "Str1\n" << str1;
cout << "\nStr2" << str2;

copystr(str2,str1);

cout << "\nThe String is copied in aray 2\n" << str2;

}
//Main Program ends

void copystr(char *s1, const char *s2)
{
while (*s2!='\0')
{
*s1++=*s2++;
}
*s1='\0';
}

No comments:

Post a Comment