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.
- to compare values, use
==
not=
. - the logical or operator
||
not|
. char p
makes room single character. can't store multi-character password inchar
variable. you'll need string.- you can't compare strings
==
.p == *password1
won't work. i'll leave figure out work. it's easy enough search for.
Comments
Post a Comment