When comparing two strings, use the function strcmp(). When the two strings are equal, 0 is returned;
When comparing strings, don't use
if(A==b)
This may make mistakes
For example, when writing draft.cpp
int queen::Level()
{
if( (18<=age && age<=25) &&
(165<=height && height<=178) &&
(sc=="火辣") &&
(yz=="漂亮"))
{
printf("女王\n"); return 1;}
}
The face value and body shape I wrote use the identity sign to judge whether they are equal. In fact, this is wrong, because I defined the face value (yz) and body (sc) in this way.
char yz[31];
char sc[31];
If you assign values to yz and sc respectively
sc="火辣";
yz="漂亮";
Hot and pretty occupies the first four bytes of these two variables, and the remaining space is 0. Therefore, it will be wrong to judge whether the two strings are the same through the identity sign.
Through gdb debugging, printing the value of sc
is like this. Because there is no initialization, garbage values will appear.