#include <conio.h>
#include <stdio.h>
#include <windows.h>



void display(void);
void menu(void);

int main()
{
    
    char username[9];
    int password=0,x=1;
    
    
    display();
    
    
    do
    {
                 
                  
                  printf("\n\t\t\tPlease enter your username:");
                  scanf("%s",username);
    
                 
                  printf("\n\n\t\t\tPlease enter your password:");
                  scanf("%d",&password);

                          //problem
                           if (username == 'udental' &&  password == 1987)
                                menu();
                           else 
                            {
                                printf("\n\n\t\t\t YOU HAVE MADE AN INVALID INPUT");
                                printf("\n\n\t\t\t      PLEASE TRY AGAIN\n\n"); 
                                Sleep (1000);
                                system("cls");
                            }
                  
                  
                  
                  
                  x++;
                  
     }while(x<4);             
    
     printf("\n\n\n\t\tSORRY BUT YOU HAVE ENTERED INCORRECT INFORMATION");
     printf("\n\n\t\t\t      GOODBYE");
      
     
    
    
    
    getch();
    return 0;
}

void display(void)
{
     
     
     printf("\n\n\t\t\tSMILES DENTAL CENTRE\n\n");
     printf("\n\n\t\t    WHERE YOU GET THE PERFECT SMILE\n\n");
     printf("\n\n\n\n\t\t       PRESS ENTER TO CONTINUE");
     getchar();
     system("cls");     
         
}

void menu(void)
{
     
     printf("\n\n\t\tWELCOME TO THE SYSTEM MENU");
     printf("\n\n\t\t   PLEASE SELECT YOUR OPTION BELOW");
}

I don't know what the problem is, but I see two glaring problems.

  1. scanf("%s", username); -- what happens if someone enters 20 characters as the user name? A: Program will most likely crash because username can only hold 8 characters. Solution: use fgets() instead of scanf() because fgets() will limit the input to the size of the buffer.
  2. scnaf("%d", &password); -- what happens of someone enters text instead of numeric data? A: the password will not be changed. Solution: Make the password a text array.

You cannot write

username == 'udental'

Use strcmp instead

You cannot write

username == 'udental'

It's not that he cannot write it. Technically speaking, it's not a syntax error but it will always be evaluated to false.
(At least my Code::Blocks compiler tells me that)

As per my knowledge, we are trying to check the equality of two char pointers of two different strings (which is always different). Hence always false

@HBK_100 #include <conio.h> Argh! The infernal and vile conio.h, please trash it! There are many alternatives to getch() And also try to avoid system calls. They are
1) Slow
2) Risky to use
3) Reduces portability of your code

@HBK_100

Unfortunately, you're wasting your time. Read his/her user title.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.