There are three errors.
The first is that a
strcpy
implementation must copy the data itself. You are not copying the data but assigning one pointer to another. While this is a valid operation, it will not give you the expected results.
The second error is that you perform the assignment using local variables passed as function parameters. These are copies of the pointers to your word strings and will therefore not change them. What you are doing is equivalent to:
char *p = word1;
char *q = word2;
q = p;
If you would print
q
now, the content of
word1
would be printed but the content of the words itself is unchanged.
The third error is in your
printf
statement where you pass characters instead of strings and have out of bound access. Using
word1[25]
accesses the character at position 25 in the string. But the
printf %s
format parameter expects a pointer to charcaters and your strings are only 25 characters wide so that index 25 is invalid (indexes are zero based so that valid ones are from zero to size-1 which is 24 in your case). It should be:
printf("This is your word1: %s\n and this is word2: %s\n",word1,word2);
You should read your course notes or books about C pointers again. Or see for example
Pointers - C++ Tutorials[
^] (don't be irritated by the C++, the basics described there apply to palin C too).