Advertisement
Guest User

Dentist System.c

a guest
Dec 24th, 2016
139
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 6.09 KB | None | 0 0
  1. //--- Header Files ----
  2. #include <stdio.h>
  3. #include <stdlib.h>
  4. #include <string.h>
  5. #include <unistd.h>  /**This library is only for unix users (Mac or Linux) for windows users this library would have to be
  6.                      replaced with the time.h library to use the sleep() function**/
  7.  
  8. #include <termios.h> /**This library is only for unix users (Mac or Linux) for windows users this library would have to be
  9.                      replaced with the conio.h library to use the getch() function**/
  10. //---------------------
  11.  
  12. //--- Function Proto-types-----
  13. void login();               //Login Function username: Admin password: P@$$w0rd (case sensitive)
  14. /**int displaymenu();       //Display the menu
  15. void menu();                //Calls the respective function based on the option selected in the menu displayed
  16. void add();                 //Allows the user to add patients into a structure array
  17. void search();              //ALlows the user to search for a patients based on patient number
  18. void display(); **/         //Displays all patient detals
  19. //---------------------------------------------------------------------------------------------------
  20.  
  21. //------------------------- MAIN FUNCTION ------------------------
  22. int main()
  23. {
  24.     int choice;
  25.     login();                //Calling the login function
  26.     //choice=displaymenu();   //Calling the display menu function and storing the return valued the the variable "choice"
  27.     //menu(choice);         //Calling the "choice" option function from the menu function
  28.     //getch();              //Holds the information on the screen until a key is pressed
  29.     return 0;
  30. }
  31. //--------------------------------------------------------------------------------------------------
  32.  
  33. //------------------- LOGIN FUNCTION -----------------------------
  34. void login()
  35. {
  36.     int i;                                       //Variable Declaration
  37.     char uid[25],pwd[25],s_uid[25]={"Admin"};    /**Created three variables one for user ID (uid[25]) and one user password
  38.                                                  (pwd[25]). s_uid[25] is the varible holding the user ID the user is suppose to
  39.                                                  enter to get in the system. Anything other that user ID (Admin) will be not
  40.                                                  have access to the system**/
  41.  
  42.     char s_pwd[25]={"p@$$w0rd"},ch=' ';          /**Created a variable (s_pwd[25]) to hold the password the user is suppose to
  43.                                                  enter to get access to the system. Anything other that user password (p@$$w0rd)
  44.                                                  will be not have access to the system. **/
  45.     puts("\n\n\n\n\n\t\t\t\t    WELCOME");
  46.     puts("\n\t\t    CHAPELTON DENTISTRY REGISTRATION SYSTEM");
  47.     puts("\n\t \t \t |-----------------------------|");
  48.     puts("\t \t \t |             LOGIN           |");
  49.     puts("\t \t \t |-----------------------------|");
  50.     printf(" \t \t \t |Enter the User ID : ");
  51.     scanf("%s",uid);
  52.     getchar();
  53.     printf(" \t \t \t |Enter the Password : ");
  54.     i=0;
  55.     while(1)     //Loops code forever
  56.     {
  57.         ch=getch();
  58.         if(ch==10)           //10 is the ASCII value for the "Enter" key. Windows users would use the value 13 instead.
  59.             break;           //Exit loop
  60.         else if(ch==127)     //127 is the ASCII value for the "backspace" key. Windows users would use the value 8 instead.
  61.         {       if(i!=0)     //This is for avoiding the input from being deleted
  62.             {
  63.                 printf("\b");       //'\b' represents blackspace escape character
  64.                 printf(" ");
  65.                 printf("\b");       //'\b' represents blackspace escape character
  66.                 i--;                //Go back to the array position that had the character that was removed by backspace
  67.                 pwd[i]='\0';        //End of array
  68.             }
  69.             else
  70.                 continue;
  71.         }
  72.         else
  73.         {
  74.             putchar('*');         //Replaces each character type by a *
  75.             pwd[i]=ch;            //Adds the character typed to the pwd array
  76.             i++;                  //Move to the next postion in the array
  77.         }
  78.     }
  79.     puts("\n \t \t \t |-----------------------------|");
  80.     pwd[i]='\0';
  81.     if((strcmp(uid,s_uid))==0 && (strcmp(pwd,s_pwd))==0) //checks if the user input is the same as what was set in the code (Admin, p@$$20rd)
  82.     {
  83.         printf("\t \t \t |\t USER AUTHENTICATED    |");
  84.         puts("\n \t \t \t |-----------------------------|");
  85.         sleep(1); //Pause the program for 1 second. Windows users would have to change this function to Sleep(1000) to get the same result
  86.         system("clear"); //"clear" is for unix users. Windows users whould use "cls" instead of "clear"
  87.     }
  88.     else
  89.     {
  90.         printf("\t \a \t \t |UNABLE TO AUTHENTICATE USER, |\n \t \t \t | \t    Try again\t       |");
  91.         puts("\n \t \t \t |-----------------------------|");
  92.         sleep(2); //Pause the program for 2 second. Windows users would have to change this function to Sleep(2000) to get the same result
  93.         system("clear"); //"clear" is for unix users. Windows users whould use "cls" instead of "clear"
  94.         fflush(stdin);
  95.         login(); //Recall the login function (Recursion)
  96.     }
  97. }
  98. //-----------------------------------------------------------------------------------------
  99.  
  100.  
  101. //------------------- GETCH FUNCTION -----------------------------
  102. /**BECAUSE UNIX SYSTEMS DON'T SUPPORT THE CONIO.H LIBRARY THAT CONTAINS IT'S OWN BUILT IN GETCH() FUNCTION
  103. WE HAVE TO MANUALLY BUILD A GETCH FUNCTION SUPPORTED BY THE TERMIOS.H LIBRARY. WINDOWS USERS CAN USE INCLUDE
  104. THE CONIO.H AND REMOVE THIS FUNCTION**/
  105.  
  106. int getch(void)
  107. {
  108.     struct termios oldattr, newattr;
  109.     int ch;
  110.     tcgetattr( STDIN_FILENO, &oldattr );
  111.     newattr = oldattr;
  112.     newattr.c_lflag &= ~( ICANON | ECHO);//knock down keybuffer
  113.     tcsetattr( STDIN_FILENO, TCSANOW, &newattr );
  114.     system("stty -echo");//shell out to kill echo
  115.     ch = getchar();
  116.     system("stty echo");
  117.     tcsetattr( STDIN_FILENO, TCSANOW, &oldattr );
  118.     return ch;
  119. }
  120. //-----------------------------------------------------------------------------------------
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement