We're a community of 1077K IT Pros here for help, advice, solutions, professional growth and fun. Join us!
1,076,478 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Start New Discussion Reply to this Discussion

Simple Login

I'm having a little problem regarding this log-in program.

#include<stdio>
#include<conio>
#define p printf
#define s scanf

main()
{

    char pass[20];
    char user[20];

    clrscr();

    p("\nEnter your username: ");
    s("%s", user);

    p("\n\nEnter your password: ");
    s("%s",  pass);

    if(user=="abel" && pass=="pass")
        p("\nW E L C O M  E !!");
    else
        p("\nINVALID INFORMATION!!");

  getch();
  return 0;
}

Even if I enter the correct username (user) and password(pass), it would still goes directly to the else statement. Logic error, or am I missing something.

Thanks!!

2
Contributors
1
Reply
25 Minutes
Discussion Span
9 Months Ago
Last Updated
2
Views
abelingaw
Posting Whiz in Training
227 posts since Jun 2008
Reputation Points: 79
Solved Threads: 31
Skill Endorsements: 2

if(user=="abel" && pass=="pass")

Look up how to compare strings again. You need to use strcmp()

And remove your 2 #define's. They make the code harder to understand, not easier.

WaltP
Posting Sage w/ dash of thyme
Team Colleague
11,404 posts since May 2006
Reputation Points: 3,421
Solved Threads: 1,055
Skill Endorsements: 37

This article has been dead for over three months: Start a new discussion instead

Post: Markdown Syntax: Formatting Help
 
You
 
© 2013 DaniWeb® LLC
Page rendered in 0.0556 seconds using 2.65MB