It would be good, if you could make your compiler more verbose.
comparison with string literal results in unspecified behaviour |
( (*pointer2).weapon !="rock" )
The
weapon
is member of
Player
. It is an array of char.
The
"rock"
is a literal string constant.
Therefore, the above code is almost same as:
1 2 3 4
|
char* lhs = (*pointer2).weapon;
const char* rhs = "rock";
( lhs != rhs )
|
That does not compare words. That compares two
addresses.
The compiler states "unspecified behaviour" and a "crush" fulfills that promise.
The addresses are probably different and therefore the inequality is
true
.
Since both players have 0 points, a tie it is.
If you have to compare two C-strings, then you have to use C functions:
http://www.cplusplus.com/reference/cstring/strncmp/
With C-strings you would use string copy rather than memcpy:
http://www.cplusplus.com/reference/cstring/strncpy/
Why do you memcpy anyway? You can print 'name' directly.
To read into array. See the importance of
width in
http://www.cplusplus.com/reference/istream/istream/operator-free/
Note that
cin
and
stdio
are distinct. There is no reason to flush stdin.
Note that
(*pointer2).weapon
and
pointer2->weapon
mean the same.
Get rid of global variables (players, pointer1, pointer2 on line 13). You can declare these local, in main().
You check mastery (lines 32-33) before any games. Points are
uninitialized.
Unknown values.
If your C-string comparisons were right, then you would +=1 or -=1 unknown values.
Are you forced to use pointers too? C++ has
by reference parameters.