problem with login thingy....

This is a discussion on problem with login thingy.... within the C Programming forums, part of the General Programming Boards category; whenever i log in as admin... then logout... it automatically logs in as student and shows the student menu.... i ...

  1. #1
    Registered User
    Join Date
    Mar 2009
    Posts
    39

    problem with login thingy....

    whenever i log in as admin... then logout...
    it automatically logs in as student and shows the student menu....
    i can figure out why... here's my main code... if you want to see the rest of the code, ill post but i think its only in my main.... any suggestions?

    Code:
    int main(void)
    {
    	STUDENT array[20];
    	char username[50];
    	char password[50];
    	char option;
    	int slot;
    	int i;
    
    	for(i = 0; i < 20; i++)
    	{
    		array[i].stud_num = 0;
    	}
    
    	clrscr();
    
    	while(strcmp(username,"quit") != 0 || strcmp(password,"quit") != 0)
    	{
    
    	login(username, password);
    
    	for(slot = 0; slot < 20; slot++)
    	{
    		if(atoi(username) == array[slot].stud_num && atoi(password) == array[slot].stud_num)
    			break;
    	}
    
    	if(strcmp(username, "ADMIN") == 0 && strcmp(password, "admin") == 0)
    	{
    		option = '0';
    
    		while(option != 'x')
    		{
    			option = admin();
    
    			switch(option)
    			{
    				case '1' :
    				{
    					gotoxy(14,48); printf("Redirecting to [Add Student] Function --->...");
    					getche();
    					add_student(array);
    					break;
    				}				//end of case '1'
    
    				case '2' :
    				{
    					gotoxy(14,48); printf("Redirecting to [Modify Student Account] Function --->...");
    					getche();
    					modify_student(array);
    					break;
    				}				//end of case '2'
    
    				case '3' :
    				{
    					gotoxy(14,48); printf("Redirecting to [Delete Student Account] Function --->...");
    					getche();
    					delete_student(array);
    					break;
    				}				//end of case '3'
    
    				case '4' :
    				{
    					gotoxy(14,48); printf("Redirecting to [Search Student Account] Function --->...");
    					getche();
    					search_student(array);
    					break;
    				}				//end of case '4'
    
    				case '5' :
    				{
    					gotoxy(14,48); printf("Redirecting to [Display all Accounts] Function --->...");
    					getche();
    					display_students(array);
    					break;
    				}				//end of case '5'
    
    				case '6' :
    				{
    					gotoxy(14,48); printf("Redirecting to [Delete all Accounts] Function --->...");
    					getche();
    					delete_all(array);
    					break;
    				}				//end of case '6'
    
    
    				case '7' :
    				{
    					gotoxy(14,50); printf("Logging out...");
    					getche();
    					option = 'x';
    					break;
    				}				//end of case '7'
    
    				case 'x' :
    				{	gotoxy(14,48); printf("Terminating Program...");
    					getche();
    					return 0;
    				}				//end of case '8'
    
    				default :
    				{	printf("\n\nInvalid option");
    				}  				//end of default
    			}					//end of switch
    		}						//end of while(option != '6')
    	}							//end of if
    
    	else if(atoi(username) == array[slot].stud_num && atoi(password) == array[slot].stud_num)
    	{
    		option = '0';
    		while(option != 'x')
    		{
    			option = student();
    
    			switch(option)
    			{
    				/*case '1' :
    				{
    					gotoxy(14,48); printf("Redirecting to [View Personal Profile] Function --->...");
    					getche();
    					view_account(array);
    					break;
    				}				//end of case '1'
    
    				/*case '2' :
    				{
    					gotoxy(14,48); printf("Redirecting to [Modify Name] Function --->...");
    					getche();
    					modify_name(array);
    					break;
    				}				//end of case '2'*/
    
    				/*case '3' :
    				{
    					gotoxy(14,48); printf("Redirecting to [Modify Birthdate] Function --->...");
    					getche();
    					modify_bday(array);
    					break;
    				}				//end of case '3'*/
    
    				/*case '4' :
    				{
    					gotoxy(14,48); printf("Redirecting to [Modify Course] Function --->...");
    					getche();
    					modify_course(array);
    					break;
    				}				//end of case '4'*/
    				case '5' :
    				{
    					gotoxy(14,50); printf("Logging out...");
    					getche();
    					option = 'x';
    					break;
    				}				//end of case '5'
    
    				case 'x' :
    				{
    					gotoxy(14,50); printf("Terminating program...");
    					getche();
    					return 0;
    				}				//end of case 'x'
    
    				default :
    				{	printf("\n\nInvalid option");
    				}
    			}					//end of switch
    		}						//end of while(option != 'x')
    	}							//end of else if
    
    	else
    	{
    		if(strcmp(username,"quit") != 0 && strcmp(password,"quit") != 0)
    		{
    			gotoxy(19,30); printf("Invalid username or password.");
    		}
    
    	}
    	}							//end of super big loop! XD haha
    
    	gotoxy(19,31); printf("Terminating Program...");
    	getche();
    	return 0;
    }

  2. #2
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    atoi returns 0 if you give it something that isn't a number, I believe.

    --
    Mats
    Compilers can produce warnings - make the compiler programmers happy: Use them!
    Please don't PM me for help - and no, I don't do help over instant messengers.

  3. #3
    Registered User
    Join Date
    Mar 2009
    Posts
    39
    thanks sir... that makes a lot of sense....
    since i initialized every stud num in the array to 0... then at first [no accounts created therefore] slot is always 0 and array[slot].stud_num is also zero [initialized] that equals to atoi...

    any suggestions sir?

  4. #4
    ATH0 quzah's Avatar
    Join Date
    Oct 2001
    Posts
    14,826
    If it's automatically reading input you aren't expecting, then it's as I said in your other thread: fix the way you read input. You aren't actually showing us your login function in your example. But I'd wager that it's leaving a newline in the input stream.


    Quzah.
    Hope is the first step on the road to disappointment.

  5. #5
    Registered User
    Join Date
    Sep 2006
    Posts
    8,868
    Quote Originally Posted by quzah View Post
    If it's automatically reading input you aren't expecting, then it's as I said in your other thread: fix the way you read input. You aren't actually showing us your login function in your example. But I'd wager that it's leaving a newline in the input stream.


    Quzah.
    That's exactly right. He needs to change the scanf("%c"), to scanf(" %c"), to fix that. (Note the added space Huskar). This only will fix it for correct input, however. It's not a robust "input fixer-upper", at all.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. WS_POPUP, continuation of old problem
    By blurrymadness in forum Windows Programming
    Replies: 1
    Last Post: 04-20-2007, 06:54 PM
  2. simple login program problem
    By suckss in forum C Programming
    Replies: 11
    Last Post: 11-11-2006, 04:02 PM
  3. Please Help - windows login domain problem
    By pritin in forum Tech Board
    Replies: 1
    Last Post: 07-23-2006, 05:35 AM
  4. Laptop Problem
    By Boomba in forum Tech Board
    Replies: 1
    Last Post: 03-07-2006, 05:24 PM
  5. half ADT (nested struct) problem...
    By CyC|OpS in forum C Programming
    Replies: 1
    Last Post: 10-26-2002, 08:37 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21