Processing Strings without cstring header file

Joined
Jan 23, 2010
Messages
1
Reaction score
0
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!

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++)
		;
}
Thank you!
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,994
Messages
2,570,223
Members
46,810
Latest member
Kassie0918

Latest Threads

Top