Thread: what function does this?

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

    what function does this?

    the thing is... i want to "redirect" the one colored in RED to the one colored in BLUE...
    how? thanks!
    P.S. Sorry for my noobish questions, its my first sem in C... srry

    Code:
    #include <stdio.h>
    #include <string.h>
    
    typedef struct student_profile{
    	long long int stud_num;
    	char name[50];
    	char bday[50];
    	char course[50];
    	} STUDENT;
    
    void login(char username[], char password[]);
    char admin(void);
    	void add_student(STUDENT array[20]);
    	void display_students(STUDENT array[20]);
    
    
    //*******************************************************************
    
    int main(void)
    {
    	STUDENT array[20];
    	char username[50];
    	char password[50];
    	char option = '0';
    	char option2;
    	int i;
    
    	for(i = 0; i < 20; i++)
    	{
    		array[i].stud_num = 0;
    	}
    
    	clrscr();
    	login(username, password);  //<------------------******HERE HERE HERE HERE*****
    
    	if(strcmp(username, "ADMIN") == 0 && strcmp(password, "admin") == 0)
    	{
    		while(option != '6')
    		{
    			option = admin();
    
    			switch(option)
    			{
    				case '1' :
    				{	clrscr();
    					printf("\n\nAdd Student Function is chosen.");
    					getche();
    					add_student(array);
    					break;
    				}				//end of case '1'
    
    				case '4' :
    				{
    					clrscr();
    					printf("\n\nDisplay all Student Entries Function is chosen.");
    					getche();
    					display_students(array);
    					break;
    				}				//end of case '4'
    
    				case '5' :
    				{
    						//******SUPPOSED TO BE LOGOUT******
    				}
    
    				case '6' :
    				{	printf("\n\nTerminating Program...");
    					break;
    				}				//end of case '6'
    
    				default :
    				{	printf("\n\nInvalid option");
    				}  				//end of default
    			}
    		}
    	}
    
    	else if(strcmp(username, "quit") == 0 || strcmp(password, "quit") == 0)
    	{
    		gotoxy(19,24); printf("Terminating Program...");
    		getche();
    		return 0;
    	}
    
    	else
    	{
    		gotoxy(19,24); printf("Invalid username or password.");
    	}
    
    	//fclose(file);
    
    	getche();
    	return 0;
    }
    
    //*******************************************************************
    
    void login(char username[], char password[])
    {
    	clrscr();
    	gotoxy(19,5);  printf("********* ********    ***     *** *********");
    	gotoxy(19,6);  printf("**    ***  **    ***   ***   ***  **    ***");
    	gotoxy(19,7);  printf("**     **  **     ***  ***   ***  **     **");
    	gotoxy(19,8);  printf("***        **    ***   **** ****  ***      ");
    	gotoxy(19,9);  printf("********   *******     ** *** **  ******** ");
    	gotoxy(19,10); printf(" ********  **    ***   ** *** **   ********");
    	gotoxy(19,11); printf("      ***  **     **   **  *  **        ***");
    	gotoxy(19,12); printf("**     **  **     **   **     **  **     **");
    	gotoxy(19,13); printf("***    **  **     **   **     **  ***    **");
    	gotoxy(19,14); printf("********* ***     *** ****   **** *********");
    	gotoxy(45,40); printf("Just type 'quit' as username");
    	gotoxy(45,41); printf("to terminate program.");
    	gotoxy(45,45); printf("Student Record Management System");
    	gotoxy(19,18); printf("Enter username:");
    	gotoxy(35,18); gets(username);
    	gotoxy(19,20); printf("Enter password:");
    	gotoxy(35,20); gets(password);
    }
    
    //*******************************************************************
    
    char admin(void)
    {
    	char option;
    
    	clrscr();
    	printf("\n\n-----Welcome Administrator!!!-----\n");
    	printf("\n[1] --- Add a Student");
    	printf("\n[2] --- Modify a Student Account.");
    	printf("\n[3] --- Delete a Student Account.");
    	printf("\n[4] --- Display all Student Acount Entries.");
    	printf("\n[5] --- Logout");
    	printf("\n[6] --- Terminate Program.\n");
    
    	printf("\n\nPlease choose the task you want to perform.\n\n");
    	scanf("%c", &option);
    
    	return option;
    }
    
    //*******************************************************************
    
    void add_student(STUDENT array[20])
    {
    	int i;
    	int empty;
    	char opt = 'y';
    
    	while(opt == 'y'){
    	for(i = 0; i < 20; i++)
    	{
    		if(array[i].stud_num == 0)
    		{
    			empty = i;
    			break;
    		}
    	}
    
    	clrscr();
    	printf("\n==========================================");
    	printf("\n\nEnter profile information\n\n");
    	printf("==========================================");
    
    	printf("\n\nStudent Number [Username]:\t");
    	scanf("%lld", &array[empty].stud_num);
    	printf("\nName:\t\t");
    	gets(array[empty].name);
    	gets(array[empty].name);
    	printf("\nBirthdate:\t");
    	gets(array[empty].bday);
    	printf("\nCourse:\t\t");
    	gets(array[empty].course);
    	printf("\n\n=========================================");
    	printf("\n\nAccount created successfully.\n");
    	printf("\n=========================================");
    
    	printf("\n\nDo you want to enter another account?: [y for yes, else no]\n\n");
    	opt = getche(); }
    
    	printf("\n\nRedirecting to the Administrator's page...\n");
    	getche();
    }
    
    //*******************************************************************
    
    void display_students(STUDENT array[20])
    {
    	int i;
    	int j;
    
    	clrscr();
    
    	gotoxy(1,2);  printf("=====================================================================");
    	gotoxy(1,4);  printf("STUDENT NUMBER");
    	gotoxy(20,4); printf("NAME");
    	gotoxy(40,4); printf("BIRTHDATE");
    	gotoxy(60,4); printf("COURSE");
    	gotoxy(1,6);  printf("=====================================================================");
    
    	for(j = 8, i = 0; array[i].stud_num != 0; j = j+2, i++)
    	{
    		gotoxy(1,j);  printf("%lld", array[i].stud_num);
    		gotoxy(20,j); puts(array[i].name);
    		gotoxy(40,j); puts(array[i].bday);
    		gotoxy(60,j); puts(array[i].course);
    	}
    
    	printf("\n\n=====================================================================");
    
    	printf("\n\nRedirecting to the Administrator's Page...\n");
    	getche();
    }
    
    //*******************************************************************

  2. #2
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    There is no "function" for this. You need another loop, or re-arrange the code. I'd suggest you re-arrange the code.

    So, add a variable to say if the user is "logged in" or not, move the "ask for password" to inside your main loop. Initialize your logged in variable to "not logged in", and change it once you have a valid username/password pair to "logged in".

    Then when user gives '5' as the answer to your menu, set your variable to "not logged in".

    --
    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
    C++まいる!Cをこわせ!
    Join Date
    Oct 2007
    Location
    Inside my computer
    Posts
    24,654
    You need to get up-to-date with the code. Get rid of gets (see why: SourceForge.net: Gets - cpwiki).
    And preferably also get rid of gotoxy and getche, as they are non-standard.
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Compiling sample DarkGDK Program
    By Phyxashun in forum Game Programming
    Replies: 6
    Last Post: 01-27-2009, 03:07 AM
  2. Seg Fault in Compare Function
    By tytelizgal in forum C Programming
    Replies: 1
    Last Post: 10-25-2008, 03:06 PM
  3. Another syntax error
    By caldeira in forum C Programming
    Replies: 31
    Last Post: 09-05-2008, 01:01 AM
  4. Replies: 28
    Last Post: 07-16-2006, 11:35 PM
  5. const at the end of a sub routine?
    By Kleid-0 in forum C++ Programming
    Replies: 14
    Last Post: 10-23-2005, 06:44 PM