Hello everyone,
I'm new to C++ and trying to write a strcpy function using pointers, instead of including the <cstring> library. My code compiles but crashes at runtime. If anyone has any tips for me, I would greatly appreciate it!
Thank you!
I'm new to C++ and trying to write a strcpy function using pointers, instead of including the <cstring> library. My code compiles but crashes at runtime. If anyone has any tips for me, I would greatly appreciate it!
Code:
#include<iostream>
using std::cout;
using std::endl;
void mystrcpy( char *,const char *);
int main()
{
char *test1 = "popcorn";
char *test2 = "candy";
mystrcpy(test1, test2);
cout << "test1 is ";
cout << *test1;
system("pause");
return 0;
}
void mystrcpy(char *word1, const char *word2)
{
for (;(*word1=*word2) !='\0'; word1++, word2++)
;
}