#include <stdio.h> void main(void) { char **input_pass; scanf("%s", &input_pass); if (input_pass == "123") { return printf("Equals"); } else { return printf("You made mistake"); } } 

I do not understand why there is an error. If I enter 123 displays "You made mistake". If I enter something else, it displays "You made mistake" and an error: Error screenshot

Thanks to all. Here's how to solve the problem:

 #include <stdio.h> #include <string.h> int main() { char **input_pass; char main_pass[] = "123"; scanf("%s", &input_pass); if (strcmp(&input_pass, &main_pass)==0) { return printf("Equals"); } else { return printf("You made mistake"); } return 0; } 
  • Thank you all for your help. Your advice helped a lot! - Vladimir
  • No, the problem is not solved at all. First, your code is not going at all. But even if you can compile it - the entered data is still being planted in an arbitrary area of ​​memory. The fact that the code works in one case doesn’t mean absolutely nothing, in the other case it will format the hard drive, having previously published all your logins / passwords on a public resource. - PinkTux
  • Your comment is valuable to me. I would like to ask you to provide more information where I could find more information about this problem. How to make so that the entered data are not planted in an arbitrary area of ​​memory? - Vladimir
  • For starters, in any beginner C tutorial / manual. You can create a new question with the “final” code, since it already has nothing to do with the original question and it’s not the case to raise an educational program here. - PinkTux
  • A new question asked here [ ru.stackoverflow.com/questions/574709/… - Vladimir

2 answers 2

What exactly is the matter?

Here it is:

 if (input_pass == "123") 

You are comparing two addresses in memory (pointer) that are obviously not equal. To compare strings in C, the functions of the strcmp () family are used .

Well, to the heap: you have a complete mess with memory and pointers. You pass to the scanf function that it is not clear that the input goes to an arbitrary memory location ...

    Strings must be compared via the strcmp function. Comparing with == you are comparing addresses, not the lines themselves. Moreover, even the same string literals are not required to be located at the same addresses, i.e. It is quite possible that "abc" == "abc" will give a lie.