In: Computer Science
Implement the Cstring function strcpy(dest, source) in c++. Do not use the library. The copy process will only stop at the last "\0". Make sure dest is large enough
Please find the answer below.
Please do comments in case of any issue. Also, don't forget to rate
the question. Thank You So Much.
code.cpp
#include <iostream>
using namespace std;
void strcpy(char **dest,char * source){
int length=0;
while(source[length]!='\0'){
length++;
}
*dest = new char[length+1];
length=0;
while(source[length]!='\0'){
(*dest)[length] =
source[length];
length++;
}
dest[length] = '\0';
}
int main( ){
char *dest=0;
char source[10]="hello";
strcpy(&dest,source);
cout<<"Destination now : "<<dest;
return 0;
}