c - Weird error, comparing a char to a string (p == "cancel") -


i'm trying basic if statement , i'm getting weird error string.

error 1:

comparison between pointer , integer ('int' , 'char *')

error 2:

result of comparison against string literal unspecified (use strncmp instead)

here copy of function occurs in.

int logon(int *par) {     char p;     printf("log student records system\nenter password or type cancel leave\n>");     scanf("%s", &p);          if(p == *password1 | p ==  *password2 | p ==  *password3)         {             *par = 2;         }         else if (p = "cancel")         {             *par = 3;         }         else         {             printf("\nincorrect password try again\n");         }      return 0; } 

the error occurring on else if statement line (p = "cancel").

there number of things wrong here.

  1. to compare values, use == not =.
  2. the logical or operator || not |.
  3. char p makes room single character. can't store multi-character password in char variable. you'll need string.
  4. you can't compare strings ==. p == *password1 won't work. i'll leave figure out work. it's easy enough search for.

Comments

Popular posts from this blog

facebook - android ACTION_SEND to share with specific application only -

python - Creating a new virtualenv gives a permissions error -

javascript - cocos2d-js draw circle not instantly -