char pass = "password";
You're trying to assign a string to a char
. That won't work! Instead, you need need to declare pass
as a char[]
like this:
char pass[] = "password";
Next problem:
if(argc == pass)
argc
is the number of command line arguments passed to your program (including the program name as the first). What you want is argv
, which contains the actual arguments. Specifically, you probably want argv[1]
.
You can't just go argv[1] == pass
as that compares the location of the two strings. To compare strings, you need to use strcmp()
. This function compares two strings and returns 0 if they're equal (there's good reason for that, but leave it for now). The former is like comparing two houses by checking if they have exactly the same street address; the latter is like comparing the houses with each other brick-by-brick. (sniped from @caf)
So the line becomes:
if (strcmp(argv[1], pass) == 0)
Put those fixes together and it should work. Please also work on improving the indentation of your code. It'll make it much easier to read, not only for others but yourself in a few weeks time.