You did not initialize pass to specify a buffer or other place to store input.
For something simple, you can declare pass as a char array instead of a pointer:
char pass[N]; // where N is large enough to hold the password plus a 0 terminator scanf("%s", pass); if (strcmp(pass, "acopio") == 0) { ... }
_Alignof it is an operand of the sizeof , _Alignof or unary & or string literal operators to initialize another array in the declaration, an expression of type "N-element array" from T will be converted ("decay") to an expression of type "pointer to T ", and the value of the expression will be the address of the first element of the array.
When you pass pass as arguments to scanf and strcmp , the type of the pass expression is converted from "N-element array of char " to "pointer to char ", and the value of the expression is the address of the first pass element or &pass[0] . Therefore, you do not need to use the & operator in a scanf call.
Similarly, in the strcmp call strcmp string literal "acopio" is converted from an expression of the type "7-element char array" ( const char in C ++) to "pointer to char ",
John Bode Nov 06 2018-12-12T00: 00Z
source share