Why does not work? Help me please!

It doesn't work and I don't know why.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
printf("  Oturum Acma\n\n");
char nickname[30],parola[30],ad[30],soyad[30];
printf("Nickname'inizi giriniz: ");
scanf("%s",nickname);
printf("Parolanizi giriniz: ");
scanf("%s",parola);
printf("Adinizi giriniz: ");
scanf("%s",ad);
printf("Soyadinizi giriniz: ");
scanf("%s",soyad);
printf("----------\n"); 
if(nickname=="hello" && parola=="world")
	{
	printf("Giris basarili.\nHosgeldiniz, sayin %s %s",ad,soyad);
	}
else
	{
	printf("Giris basarisiz.\nLutfen tekrar deneyiniz veya uye olunuz.");
	}
You can't compare c-strings like this
if(nickname=="hello" && parola=="world")

If you absolutely must use c-strings then you would need strcmp:
http://www.cplusplus.com/reference/cstring/strcmp/

However, you would be much better using std::string, which would also allow you to use == for testing equality.


BTW, I'm guessing what you might mean by "It doesn't work". I think you would get a better response if you stated what you actually meant by that. Also, it would help if you posted a complete, (ideally) compileable/runnable code to test in cpp.sh.
I tried to make a simple logging system. I wrote codes. When I enter to my account[Nickname: hello
- Parola(password): world] it shows "Giris basarisiz. Lutfen tekrar deneyiniz veya uye olunuz.".
I enter rightly but it says "You enter wrongly". I hope you got me. :)
Last edited on
For minimal change, replace
if(nickname=="hello" && parola=="world")
with
if ( !strcmp( nickname, "hello" ) && !strcmp( parola, "world") )

(You will need header <cstring>).

However, I'd be inclined to use std::string rather than c-strings.

(My Turkish is almost non-existent!)
Can you show me how to do? I actually don't know this function(!strcmp). I am new. I hope, you can help me.
Look at the previous link, it shows you how to use strcmp()

All "!" does is say if the result comes back true, make it false. If it comes back false, make it true.
I got it. Thanks for everything. Have a good day. :)
Topic archived. No new replies allowed.