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"); }
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' )
If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
If at first you don't succeed, try writing your phone number on the exam paper.
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"); }
HOPE YOU UNDERSTAND.......
By associating with wise people you will become wise yourself
It's fine to celebrate success but it is more important to heed the lessons of failure
We've got to put a lot of money into changing behavior
PC specifications- 512MB RAM, Windows XP sp3, 2.79 GHz pentium D.
IDE- Microsoft Visual Studio 2008 Express Edition
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.
If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
If at first you don't succeed, try writing your phone number on the exam paper.
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
HOPE YOU UNDERSTAND.......
By associating with wise people you will become wise yourself
It's fine to celebrate success but it is more important to heed the lessons of failure
We've got to put a lot of money into changing behavior
PC specifications- 512MB RAM, Windows XP sp3, 2.79 GHz pentium D.
IDE- Microsoft Visual Studio 2008 Express Edition
i dont know programming even C.i try to make something simple only for learn how to use if,char,int.the first steps =]