strcmp with pointers not working in C

前端 未结 6 1317
情话喂你
情话喂你 2020-12-20 17:39

Why this code isn\'t working. Just trying to check if the user input is the same as a password

char *pass;

printf(\"Write the password: \");
scanf(\"%s\", p         


        
6条回答
  •  清酒与你
    2020-12-20 18:28

    pass is an unitialized pointer, and you attempt to write into it. You have to allocate enough memory to hold a string. For example, char pass[SIZE] will work better.

提交回复
热议问题