but can not understand else.anything i give to it,tells me well done.Code:#include <stdio.h>
main()
{
char a,sk8;
printf("give password:");
scanf("%c",&a);
a=sk8;
if (a=sk8)
printf("well done\n");
else
printf("wrong password\n");
}
Printable View
but can not understand else.anything i give to it,tells me well done.Code:#include <stdio.h>
main()
{
char a,sk8;
printf("give password:");
scanf("%c",&a);
a=sk8;
if (a=sk8)
printf("well done\n");
else
printf("wrong password\n");
}
if (a=sk8)
Use == for comparing, = for assignment.
You've written (essentially)
if ( (a=sk8) != '\0' )
ok.i change if but the same problemCode:#include <stdio.h>
main()
{
char a,sk8;
printf("give password:");
scanf("%c",&a);
a=sk8;
if (a==sk8)
printf("well done\n");
else
printf("wrong password\n");
}
a=sk8;
if (a==sk8)
Where between these two statements do you expect a to change to something different from sk8?
You have
if ( 1 == 1 )
for all that's worth.
And besides, you make sure a and sk8 are the same thing directly above that line, by assigning the current value of sk8 to a (discarding the typed-in value you had just read).
sk8 is the password.i initialize it char because is a character.sorry for my english but i dont know to speak verry well =[
so a=sk8; is not needed because i initialize it into if.wright?
yes. First initialize it
i dont know programming even C.i try to make something simple only for learn how to use if,char,int.the first steps =]
You need a good book and more reading. Your current understand is too weak for attempting any kind of programming with C.
Also, main must return int. So in effect, your
main()
must be written as
int main()
And for heaven's sake, indent your code!