You need to have some place to put the string first. So, in your example:
Code:
char* someString;
char* anotherString = "devshed";
The char pointer someString has not been initialized. If you declared it outside of a function, then it most likely contains the value 0x0000:0x0000, which has it pointing right at the beginning of the Interrupt Vector Table. If you start copying strings there, you're guaranted to crash the system, which is one reason why it's protected (ie, by the segmentation fault, which says that you are trying to access memory that is not yours to access -- in the good old days of DOS, the error message would have been the system crashing).
So, you need to allocate enough memory to contain the string and then have someString point to it. In the case of anotherString, the compiler did this for you; in static memory it allocated a string 8 characters long, copied "devshed" into it followed by a NUL (the null-terminator, '\0', which marks the end of the string -- this is an absolute necessity in C/C++ strings), and then placed the address of that string in anotherString. So, your strcpy code should read something like:
Code:
char* someString;
char* anotherString = "devshed";
someString = (char*)malloc(strlen(anotherString)+1);
// always need to add one for the null-terminator
// in C++, use new instead of malloc:
// someString = new char [strlen(anotherString)+1];
strcpy(someString, anotherString); // now the string has somewhere to go!
When you tried this:
Code:
char someString[] = "";
you did the same as you did above with anotherString, except the compiler only allocated one byte and that single byte contains the null-terminator. Then right after it in memory are other of your program's variables. So when you strcpy the string into that single-char buffer, the rest of the string overwrites the variables that follow it in memory. This is called "clobbering". What's even more fun is when you clobber local variables inside of a function, because then you very well could also be clobbering the function's return address, which will cause the program to "mysteriously" crash -- yeah, I've done that trick a few times! That is why when you do a strcpy or sprintf or the like, you want to be very sure that the buffer you are copying or writing to is big enough to hold the string.
BTW, this form of clobbering is also called "buffer overflow" and "over-running a buffer", which is a common program error that hackers exploit to take over systems; basically, they overflow the buffer and insert into the right location a return address that points to their own code that they've inserted (they studied just where that would be in order to perform the exploit). So a hot topic now is how to write your C/C++ code so that it protects itself against buffer overflow.
Hope all that helps!