Thread: Why am I getitng these errors? (Library information system)

  1. #1
    Registered User GeorgeIO's Avatar
    Join Date
    Nov 2017
    Posts
    33

    Question Why am I getitng these errors? (Library information system)

    Hi there. I'm currently working on a project to design a library information system.

    Hi there. I'm in the process of trying to make a library information system in C. The library has to store information about the books it keeps, the students who use the library, and a record of books that are borrowed.

    The following should be implemented (and whatever else I feel would be suitable to add):


    • books to be added and removed from the library
    • students to register with the library
    • students to search the library for books
    • students to borrow and return books.


    It's a rather large project (as you can see), assigned to me at University. The aim should be to make the program modular, and easy to read. I am yet to achieve the modular part (header files etc) because I'm stuck with two errors I can't get my head round. I'm fairly new to programming, but have become quite proficient in C in the last few months.

    I'll warn you now, there is many lines of code in this program:

    Code:
    //Header files
    #include <stdio.h>
    #include <stdlib.h>
    #include <conio.h>
    #include <windows.h>
    #include <string.h>
    
    //Function prototypes
    int lib_main(void);
    int gotoxy(int x, int y);
    int developer_info();
    int window();
    int change_lib_pass();
    int finish();
    int pass();
    int student_pass();
    int lib_signup();
    int admin_signin();
    int get_password(char* pass);
    int lib_main_book(void);
    int lib_main_student(void);
    int add_books(void);
    int search_books();
    int edit_books();
    int delete_books();
    int view_books();
    int add_student(void);
    int search_student();
    int edit_student();
    int delete_student();
    int view_student();
    int add_window();
    int get_data(int choice);
    int student_pass_remove();
    int student_main(void);
    int getdata_student(int choice);
    int checkid(int t);
    int checkid_admin(int d);
    
    
    
    
    //list of global variable
    char choice;
    FILE *login;
    char findBook;
    char password[10];
    int x = 15;
    //-----------------------------Main Interface functions-----------------------------------------------------
    int main(){
        SetConsoleTitle("Library Information System");
        system("cls");
        window();
        gotoxy(34,4);printf("Login Area");
        gotoxy(20,10);printf("1. Librarian");
        gotoxy(45,10);printf("2. Student");
        gotoxy(20,12);printf("3. Developer Info");
        gotoxy(45,12);printf("9. Exit");
        gotoxy(15,23);printf("Enter your choice: ");
        choice  = getche(); // input from keyboard
        system("cls");      //use to clear windows
        window();           // for title message
        switch(choice)
        {
        case '1':
        pass(); lib_main();
        break;
    
        case '2':
        student_pass();
        break;
    
        case '3':
        developer_info();
        break;
    
        case '9':
        finish();
        break;
    
        default :
        gotoxy(20,17);printf("Could not verify input. Please try again");
        main();
        };
        return 0;
    }
    
    int lib_main(void){
        system("cls"); window();
        gotoxy(32,4);printf("Admin Workspace");
        gotoxy(15,10);printf("1. Book Info");
        gotoxy(35,10);printf("2. Student Info");
        gotoxy(15,12);printf("3. Student Password");
        gotoxy(55,10);printf("8. Back");
        gotoxy(55,12);printf("9. Exit");
        gotoxy(15,23);printf("Enter your choice: ");
        choice  = getche();
    
        switch(choice)
        {
        case '1':
        lib_main_book();
        break;
    
        case '2':
        lib_main_student();
        break;
    
        case '3':
        change_lib_pass();
        break;
    
        case '8':
        main();
        break;
    
        case '9':
        finish();
        break;
    
        default :
        lib_main();
        };
    }
    
    int lib_main_book(void){
        while(1){
            system("cls");
            window();
            gotoxy(35,4);printf("Admin Area");
            gotoxy(x,6);printf("1. Add Book");
            gotoxy(x,8);printf("2. Search Book");
            gotoxy(x,10);printf("3. Modify Book Record");
            gotoxy(x,12);printf("4. Delete Book Record");
            gotoxy(x,14);printf("5. View book list");
            gotoxy(x,20);printf("8. Back");
            gotoxy(25,20);printf("9. Exit");
            gotoxy(x,23);printf("Enter your choice: ");
            choice  = getche();
    
            switch(choice){
                case '1':
                    add_books();
                    break;
                case '2':
                    search_books();
                    break;
                case '3':
                    edit_books();
                    break;
                case '4':
                    delete_books();
                    break;
                case '5':
                    view_books();
                    break;
                case '8':
                    system("cls"); lib_main();
                    break;
                case '9':
                    finish();
                    break;
                default:
                    break;
            };
        };
    
    }
    
    int lib_main_student(void){
        while(1){
        system("cls"); window();
            gotoxy(35,4);printf("Admin Area");
            gotoxy(x,6);printf("1. Add Student");
            gotoxy(x,8);printf("2. Search Student");
            gotoxy(x,10);printf("3. Modify Student Record");
            gotoxy(x,12);printf("4. Delete Student Record");
            gotoxy(x,14);printf("5. View All Students");
            gotoxy(x,20);printf("8. Back");
            gotoxy(25,20);printf("9. Exit");
            gotoxy(x,23);printf("Enter your choice: ");
            choice  = getche();
            switch(choice){
                case '1':
                    add_student();
                    break;
                case '2':
                    search_student();
                    break;
                case '3':
                    edit_student();
                    break;
                case '4':
                    delete_student();
                    break;
                case '5':
                    view_student();
                    break;
                case '8':
                    lib_main();
                    break;
                case '9':
                    finish();
                    break;
                default:
                    break;
            };
        };
    }
    
    
    int student_main(void){
        while(1){
            system("cls"); window();
            gotoxy(35,4);printf("You are logged in as a student");
            gotoxy(x,6);printf("1. View Book List");
            gotoxy(x,8);printf("2. Search Book");
            gotoxy(x,10);printf("3. View All Student info");
            gotoxy(x,20);printf("8. Back");
            gotoxy(25,20);printf("9. Exit");
            gotoxy(x,23);printf("Enter your choice: ");
            choice  = getche();
    
            switch(choice){
                case '1':
                    view_books();
                    break;
                case '2':
                    search_books();
                    break;
                case '3':
                    view_student();
                    break;
                case '8':
                    system("cls");
                    main();
                    break;
                case '9':
                    finish();
                    break;
                default:
                    main();
                    break;
            };
        };
    }
    
    
    //-----------------------------General Function-----------------------------------------------------
    COORD coord = {0,0}; ///set the cordinate to 0, 0 (top-left corner of window);
    int gotoxy(int x, int y){
        coord.X = x; coord.Y = y; /// X and Y coordinates
        SetConsoleCursorPosition(GetStdHandle(STD_OUTPUT_HANDLE), coord);
    }
    
    int developer_info(){       // function to show dev info
        system("cls"); window();
        gotoxy(20,6);printf("Design and Developed by....");
        gotoxy(25,8);printf("George Strawbridge");
        gotoxy(25,9);printf("School of Computing");
        gotoxy(25,10);printf("University of Leeds");
        getch(); main();
    }
    
    int window(){          // function for show software info altime
        gotoxy(15,1); printf("*****Library Information System*****");
        gotoxy(5,2);printf("________________________________________________________");
     }
    
    int change_lib_pass(){    // function for Admin Password change
        system("cls"); window();
        FILE *login;
        char old_pass[10], new_pass[10];
        gotoxy(15,10);printf("Enter Old password: ");
        get_password(old_pass);
        gotoxy(15,12);printf("Enter New password: ");
        get_password(new_pass);
        login = fopen("password.dat","rb+");
        while(fread(&password,sizeof(password),1,login)==1){
            if(strcmp(old_pass,password)==0){
                strcpy(password,new_pass);
                fseek(login,-sizeof(password),SEEK_CUR);
                fwrite(&password,sizeof(password),1,login);
                fclose(login);
                gotoxy(15,15);printf("Password sucessfully changed! ");
            }else{
                gotoxy(15,15);printf("Password changing process failed!");
            }
        }
        gotoxy(15,23);printf("press any key to go back..");
        getch(); system("cls"); window(); lib_main();
    }
    
    int finish(){          // function to Exit Message
        system("cls"); window();
        gotoxy(16,11);printf("Are you sure wanna Exit (Y/N): ");
        choice  = getche();
        if(choice == 'n' || choice == 'N'){
        system("cls");window(); main();
        }
        else{
        system("cls"); window();
        gotoxy(15,9);printf("\xB2\xB2\xB2\xB2\xB2\xB2\xB2\xB2\xB2\xB2\xB2\xB2\xB2\xB2\xB2\xB2\xB2\xB2\xB2\xB2\xB2\xB2\xB2\xB2\xB2\xB2\xB2\xB2\xB2\xB2\xB2\xB2\xB2\xB2\xB2\xB2\xB2\xB2\xB2\xB2\xB2\xB2\xB2\xB2\xB2\xB2\xB2\xB2");
        gotoxy(15,14);printf("\xB2\xB2\xB2\xB2\xB2\xB2\xB2\xB2\xB2\xB2\xB2\xB2\xB2\xB2\xB2\xB2\xB2\xB2\xB2\xB2\xB2\xB2\xB2\xB2\xB2\xB2\xB2\xB2\xB2\xB2\xB2\xB2\xB2\xB2\xB2\xB2\xB2\xB2\xB2\xB2\xB2\xB2\xB2\xB2\xB2\xB2\xB2\xB2");
        gotoxy(33,11);printf("Thank You");
        gotoxy(21,12);printf("Department of Software Enginnering");
        gotoxy(x,21);printf("Exiting in 3 second...........>");
        Sleep(3000);
        exit(0);
        }
    }
    
    int pass(){            // function for Admin Password
        login = fopen("password.dat","rb");
        if(login == NULL){
            gotoxy(10,9);printf("Unable to find librarian info in database. Sign up to become a librarian now.");
            lib_signup();
        }else{
            admin_signin();
        }
    }
    
    int student_pass(){          // function for student Password
        system("cls"); window();
        gotoxy(15,7);printf("To Enter Library you need a library pass");
        gotoxy(15,9);printf("Do you have a library pass?(Y/N): ");
        if(getch()=='n'){
        gotoxy(15,10);printf("Please contact the librarian to sign up if you don't have a pass");
        getch(); system("cls"); window(); main();
        }
        else
        {
        student_pass();
        }
    }
    
    int lib_signup(){     // function for save admin Pass
        char temp[10];
        login = fopen("password.dat","wb");
        gotoxy(10,10);printf("Enter password: ");
        get_password(password);
        gotoxy(10,11);printf("Re Enter Password: ");
        get_password(temp);
        while(strcmp(password,temp)!=0){
            gotoxy(10,10);printf("Password did not matched! Enter again");
            gotoxy(10,11);printf("Enter password: ");
            get_password(password);
            gotoxy(10,12);printf("Re Enter Password: ");
            get_password(temp);
            system("cls");
        }
        fwrite(&password,sizeof(password),1,login);
        fclose(login);
        system("cls"); window();
    }
    
    
    int admin_signin(){     // function for Admin Login part
        char temp[10];
        login = fopen("password.dat","rb");
        gotoxy(15,10);printf("Enter password: ");
        get_password(temp);
        while(fread(&password, sizeof(password),1,login)==1){
            while(strcmp(temp,password)!=0){
                system("cls"); window();
                gotoxy(15,10); printf("Password did not match!---Enter Again: ");
                get_password(temp);
            }
            gotoxy(15,12);printf("Password Match");
            break;
        }
        fclose(login);
        Sleep(1000);
        system("cls");window();
    }
    
    int get_password(char* pass){  // function for Password
        char temp_passP[25];
        int i=0;
         while(1)
        {
                temp_passP[i]=getch();
                if(temp_passP[i]==13){break;}
                else if(temp_passP[i]==8)
                {
                    if(i!=0) {
                    printf("\b \b");
                    i--;
                    } else {printf("\a");}
                }
                else
                {
                    printf("*");
                    *(pass+i) = temp_passP[i];
                    i++;
                }
                 *(pass+i)='\0';
         }
    }
    //--------------------------------------------------------------------------------------------
    
    //--------------------------Book Releted Function-------------------------------------------------
    struct BOOK             //Structure variable for BOOK
    {
        int id;
        char name[20];
        char Author[20];
        int quantity;
        float Price;
        int rackno;
        char *cat;
    };
    struct BOOK book;
    
    char catagories[][15]={"Computer","Electronics","Electrical","Civil","Mechnnical","Architecture"};
    
    int add_books(void){    //funtion for adding books
        system("cls");window();
        FILE *fp;
        int i, choice;
        system("cls"); window(); add_window();
        gotoxy(x,19); printf("Enter your choice:");
        scanf("%d", &choice);
        if(choice==7)
            lib_main_book() ;
        system("cls"); window();
        fp = fopen("Record.dat","ab+");
        if(get_data(choice) == 1){
            book.cat=catagories[choice-1];
            fseek(fp,0,SEEK_END);
            fwrite(&book,sizeof(book),1,fp);
            fclose(fp);
            gotoxy(x,17);printf("The record is sucessfully saved");
            gotoxy(x,19);printf("Save any more?(Y / N):");
            if(getch()=='n'){
                system("cls"); lib_main_book();
            }else{
                add_books();
            }
        }
        fclose(fp);
    }
    
    int add_window(){      //Function for Books Catagory Interface
        system("cls"); window();
        gotoxy(25,6);printf("******SELECT CATEGOIES******");
        gotoxy(x,9);printf("1. Computer");
        gotoxy(x,10);printf("2. Electronics");
        gotoxy(x,11);printf("3. Electrical");
        gotoxy(x,12);printf("4. Civil");
        gotoxy(x,13);printf("5. Mechanical");
        gotoxy(x,14);printf("6. Architecture");
        gotoxy(x,16);printf("7. Back");
    }
    
    int get_data(int choice){
        int x1 = 30; int bookID;
        gotoxy(x,7);printf("Enter the Information Bellow");
        gotoxy(x,9);printf("Category:");  gotoxy(x1,9);printf("%s",catagories[choice-1]);
        gotoxy(x,10);printf("Book ID:");  gotoxy(x1,10);scanf("%d",&bookID);
    
         if(book.id==bookID){
                    gotoxy(x,11);printf("Id is already Exits");
                    getch(); add_books();
                    }
    
        book.id=bookID;
        gotoxy(x,11);printf("Book Name:"); gotoxy(x1,11);scanf("%s",book.name);
        gotoxy(x,12);printf("Author:");    gotoxy(x1,12);scanf("%s",book.Author);
        gotoxy(x,13);printf("Quantity:");  gotoxy(x1,13);scanf("%d",&book.quantity);
        gotoxy(x,14);printf("Price:");     gotoxy(x1,14);scanf("%f",&book.Price);
        gotoxy(x,15);printf("Rack No:");   gotoxy(x1,15);scanf("%d",&book.rackno);
        return 1;
    }
    
    int check_id(int t)      //Function to check ID is exist or not
    {
        FILE *temp;
        temp = fopen("Record.dat","rb+");
        while(fread(&book,sizeof(book),1,temp)==1)
            if(book.id == t){
                fclose(temp);
                return 0;
            }
            fclose(temp);
            return 1;
    
    }
    
    
    int edit_books()       //Function to Edit Books info
    {
        system("cls");window();
        FILE *fp;
        int c=0,d;
        gotoxy(27,6);printf("****Edit Book Section****");
        while(1)
        {
            gotoxy(x,8);printf("Enter Book Id to edit:");scanf("%d",&d);
            fp=fopen("uRecord.dat","rb+");
            while(fread(&book,sizeof(book),1,fp)==1)
            {
                if(checkid_admin(d)==0)
                {
                    gotoxy(x,9);printf("The book is availble");
                    gotoxy(x,10);printf("The Book ID:%d",book.id);
                    gotoxy(x,11);printf("New name:");scanf("%s",book.name);
                    gotoxy(x,12);printf("New Author:");scanf("%s",book.Author);
                    gotoxy(x,13);printf("New quantity:");scanf("%d",&book.quantity);
                    gotoxy(x,14);printf("New price:");scanf("%f",&book.Price);
                    gotoxy(x,15);printf("New rackno:");scanf("%d",&book.rackno);
                    gotoxy(x,16);printf("The record is modified");
                    fseek(fp,ftell(fp)-sizeof(book),0);
                    fwrite(&book,sizeof(book),1,fp);
                    fclose(fp);
                    c=1;
                }
                if(c==0)
                {
                    gotoxy(x,11);printf("No record found");
                }
            }
    
        gotoxy(x,18);printf("Modify another Record?(Y/N)");
        if(getch()=='y'){
            edit_books();
        }
        else
            lib_main_student();
        }
    }
    
    
    
    int search_books(){    //Function to search books
        system("cls"); window();
        gotoxy(25,7);printf("********Search Books********");
        gotoxy(x,10);printf("1. Search By ID");
        gotoxy(x,12);printf("2. Search By Name");
        gotoxy(x,16);printf("Enter Your Choice: ");
        switch(getch())
        {
            case '1':
                searchByID();
                break;
            case '2':
                searchByName();
                break;
            default :
                getch();search_books();
        }
    }
    
    int searchByID(){      //Function to search books by given ID
        system("cls"); window();
        int id; FILE *fp;
        gotoxy(25,7);printf("*****Search Books By Id*****");
        gotoxy(x,9);printf("Enter the book id:");scanf("%d",&id);
        int findBook = 0;
        fp = fopen("Record.dat","rb");
        while(fread(&book,sizeof(book),1,fp)==1){
            if(book.id==id){
                Sleep(2);
                gotoxy(x,11);printf("The Book is available");
                gotoxy(x,13);printf("\xB2 ID:%d",book.id);
                gotoxy(x,14);printf("\xB2 Name:%s",book.name);
                gotoxy(x,15);printf("\xB2 Author:%s ",book.Author);
                gotoxy(x,16);printf("\xB2 Qantity:%d ",book.quantity);
                gotoxy(x,17);printf("\xB2 Price:%.2f",book.Price);
                gotoxy(x,18);printf("\xB2 Rack No:%d ",book.rackno);
                findBook = 1;
            }
        }
        if(findBook == 0){  //checks whether conditiion enters inside loop or not
            gotoxy(x,12);printf("\aNo Record Found");
        }
        fclose(fp);
        gotoxy(x,20);printf("Try another search?(Y/N)");
        if(getch()=='y')
            searchByID();
        else
        system("cls");window();
    }
    
    int searchByName(){    //Function to search books by using Books name
        system("cls");window();
        char s[15];
        int d=0;
        FILE *fp;
        gotoxy(25,7);printf("****Search Books By Name****");
        gotoxy(x,9);printf("Enter Book Name:");scanf("%s",s);
        fp = fopen("Record.dat","rb");
        while(fread(&book,sizeof(book),1,fp)==1){
            if(strcmp(book.name,(s))==0){ //checks whether book.name is equal to s or not
                gotoxy(x,11);printf("The Book is available");
                gotoxy(x,13);printf("\xB2 ID:%d",book.id);
                gotoxy(x,14);printf("\xB2 Name:%s",book.name);
                gotoxy(x,15);printf("\xB2 Author:%s",book.Author);
                gotoxy(x,16);printf("\xB2 Qantity:%d",book.quantity);
                gotoxy(x,17);printf("\xB2 Price:Rs.%.2f",book.Price);
                gotoxy(x,18);printf("\xB2 Rack No:%d ",book.rackno);
                d++;
            }
        }
        if(d==0){
            gotoxy(x,12);printf("\aNo Record Found");
        }
        fclose(fp);
        gotoxy(x,20);printf("Try another search?(Y/N)");
        if(getch()=='y')
        searchByName();
        else
        system("cls");window();
    }
    
    int delete_books(){    //function that delete  record form Database
        system("cls"); window();
        FILE *ft,*fp;
        char another;
        int d,findBook = 0;
        while(another = 'y'){  //infinite loop
            gotoxy(25,7);printf("********BOOK DELETE********");
            gotoxy(x,9);printf("Enter the Book ID to  delete:"); scanf("%d",&d);
            fp = fopen("Record.dat","rb+");
            while(fread(&book,sizeof(book),1,fp)==1){
                if(book.id==d){
                    gotoxy(x,11);printf("The book record is available");
                    gotoxy(x,13);printf("Book name is %s",book.name);
                    gotoxy(x,14);printf("Rack No. is %d",book.rackno);
                    findBook = 1;
                    gotoxy(x,16);printf("Do you want to delete it?(Y/N):");
                    if(getch()=='y'){
                        ft=fopen("test.dat","wb");  //temporary file for delete
                        rewind(fp);
                        while(fread(&book,sizeof(book),1,fp)==1){
                            if(book.id!=d){
                                fwrite(&book,sizeof(book),1,ft); //write all in tempory file except that
                            }                              //we want to delete
                        }
                        fclose(fp);
                        fclose(ft);
                        remove("Record.dat");
                        rename("test.dat","Record.dat"); //copy all item from temporary file to fp except that
                                            //we want to delete
                        gotoxy(x,17);printf("The record is sucessfully deleted");
                    }
                }
            }
            if(findBook == 0){
                gotoxy(x,11);printf("No record is found");
            }
    
            gotoxy(x,18);printf("Delete another record?(Y/N)");
            if(getch()=='y'){
                delete_books();
            }
            else
                lib_main_book();
        }
    }
    
    int view_books()   //I use this function to view all books info
    {
        int j;
        system("cls");window();
        FILE *fp;
        gotoxy(5,5);printf("*********************************Book List****************************");
        gotoxy(5,6);printf(" CATEGORY      ID      BOOK NAME       AUTHOR     QTY   PRICE   RackNo");
        j=8;
        fp=fopen("Record.dat","rb");
        while(fread(&book,sizeof(book),1,fp)==1){
            gotoxy(5,j);printf("%s",book.cat);
            gotoxy(19,j);printf("%d",book.id);
            gotoxy(27,j);printf("%s",book.name);
            gotoxy(44,j);printf("%s",book.Author);
            gotoxy(56,j);printf("%d",book.quantity);
            gotoxy(61,j);printf("%.2f",book.Price);
            gotoxy(71,j);printf("%d",book.rackno);
            printf("\n\n");
            j++;
        }
        fclose(fp);
        getch(); system("cls"); window();
    }
    //--------------------------------------------------------------------------------------------
    
    //------------------------------Student Releted Function for Admin-----------------------------------------------------
    struct STUDENT             //Structure variable for student
    {
        int id;
        char name[20];
        char pass[20];
        int mobile;
        float fee;
        int age;
        char *cat;
    };
    struct STUDENT student;
    
    char catagories_u[][15]={"Student","Teacher","Others"};
    
    int add_window_u(){      //Function for Student Catagory Interface
        system("cls"); window();
        gotoxy(25,6);printf("******SELECT CATEGOIES******");
        gotoxy(x,9);printf("1. Student");
        gotoxy(x,11);printf("2. Teacher");
        gotoxy(x,13);printf("3. Others");
        gotoxy(x,15);printf("7. Back");
    }
    
    
    int add_student(void){    //funtion for adding student
        FILE *fp;
        int i, choice;
        system("cls");window();
        add_window_u();
        gotoxy(x,19);printf("Enter your choice:");scanf("%d", &choice);
        if(choice==7)
            lib_main_student() ;
        system("cls");window();
        fp = fopen("uRecord.dat","ab+");
        if(getdata_student(choice) == 1){
            student.cat=catagories_u[choice-1];
            fseek(fp,0,SEEK_END);
            fwrite(&student,sizeof(student),1,fp);
            fclose(fp);
            gotoxy(x,17);printf("The record is sucessfully saved");
            gotoxy(x,19);printf("Save any more?(Y / N):");
            if(getch()=='n'){
                system("cls"); window(); lib_main_student();
            }else{
                add_student();
            }
        }
        fclose(fp);
    }
    
    
    
    
    int get_data_student(int choice)
    {
        int x1 = 30;
        int studentID;
        gotoxy(x,7);printf("Enter the Information Below");
        gotoxy(x,9);printf("Category:");  gotoxy(x1,9);printf("%s",catagories_u[choice-1]);
        gotoxy(x,10);printf("Student ID:");  gotoxy(x1,10);scanf("%d",&studentID);
    
                if(student.id==studentID){
                    gotoxy(x,11);printf("Id is already Exits");
                    getch(); add_student;
                    }
    
        student.id=studentID;
        gotoxy(x,11);printf("Student Name:");  gotoxy(x1,11);scanf("%s",&student.name);
        gotoxy(x,12);printf("Password:");gotoxy(x1,12);scanf("%s",&student.pass);
        gotoxy(x,13);printf("Mobile:");     gotoxy(x1,13);scanf("%d",&student.mobile);
        gotoxy(x,14);printf("Fee:");        gotoxy(x1,14);scanf("%f",&student.fee);
        gotoxy(x,15);printf("Age:");        gotoxy(x1,15);scanf("%d",&student.age);
        return 1;
    }
    
    
    
    
    
    
    
    
    
    int checkid_student(int t)      //Function to check ID is exist or not
    {
        FILE *temp;
        temp = fopen("uRecord.dat","rb+");
        while(fread(&student,sizeof(student),1,temp)==1)
            if(student.id == t){
                fclose(temp);
                return 0;
            }
            fclose(temp);
            return 1;
    
    }
    
    int edit_student()       //Function to Edit student info
    {
        system("cls");window();
        FILE *fp;
        int c=0,d;
        gotoxy(27,6);printf("****Edit Student Section****");
        while(1)
        {
            gotoxy(x,8);printf("Enter Admin Id to edit:");scanf("%d",&d);
            fp=fopen("uRecord.dat","rb+");
            while(fread(&student,sizeof(student),1,fp)==1)
            {
                if(checkid_student(d)==0)
                {
                    gotoxy(x,9);printf("The Admin is availble");
                    gotoxy(x,10);printf("The Admin ID:%d",student.id);
                    gotoxy(x,11);printf("New Name:");scanf("%s",student.name);
                    gotoxy(x,12);printf("Password:");scanf("%s",student.pass);
                    gotoxy(x,13);printf("New Mobile:");scanf("%d",&student.mobile);
                    gotoxy(x,14);printf("New Fee:");scanf("%f",&student.fee);
                    gotoxy(x,15);printf("New Age:");scanf("%d",&student.age);
                    gotoxy(x,16);printf("The record is modified");
                    fseek(fp,ftell(fp)-sizeof(student),0);
                    fwrite(&student,sizeof(student),1,fp);
                    fclose(fp);
                    c=1;
                }
                if(c==0)
                {
                    gotoxy(x,11);printf("No record found");
                }
            }
    
        gotoxy(x,18);printf("Modify another Record?(Y/N)");
        if(getch()=='y'){
            edit_student();
        }
        else
            lib_main_student();
        }
    }
    
    int search_student(){    //Function to search student
        system("cls");window();
        gotoxy(27,7);printf("******Search Student******");
        gotoxy(x,10);printf("1. Search By ID");
        gotoxy(x,12);printf("2. Search By Name");
        gotoxy(x,14);printf("Enter Your Choice: ");
        switch(getch())
        {
            case '1':
                searchBy_student_ID();
                break;
            case '2':
                searchBy_student_Name();
                break;
            default :
                getch(); search_student();
        }
    }
    
    int searchBy_student_ID(){      //Function to search Student by given ID
        system("cls");window();
        int id; FILE *fp;
        gotoxy(27,7);printf("****Search Student By Id****");
        gotoxy(x,9);printf("Enter student id:");scanf("%d",&id);
        int find_student = 0;
        fp = fopen("studentRecord.dat","rb");
        while(fread(&student,sizeof(student),1,fp)==1){
            if(student.id==id){
                Sleep(2);
                gotoxy(x,11);printf("The student is available");
                gotoxy(x,13);printf("\xB2 ID:%d",student.id);
                gotoxy(x,14);printf("\xB2 Name:%s",student.name);
                gotoxy(x,15);printf("\xB2 Password:%s ",student.pass);
                gotoxy(x,16);printf("\xB2 Mobile:%d ",student.mobile);
                gotoxy(x,17);printf("\xB2 Fee:%.2f",student.fee);
                gotoxy(x,18);printf("\xB2 Age:%d ",student.age);
    
                find_student = 1;
            }
        }
        if(find_student == 0){  //checks whether conditiion enters inside loop or not
            gotoxy(x,12);printf("\aNo Record Found");
        }
        fclose(fp);
        gotoxy(x,20);printf("Try another search?(Y/N)");
        if(getch()=='y')
            searchBy_student_ID();
        else
            lib_main_student();
    }
    
    
    int searchBy_student_Name(){    //Function to search student by using Books name
        system("cls");window();
        char s[15];
        int d=0;
        FILE *fp;
        gotoxy(27,7);printf("****Search Student By Name****");
        gotoxy(x,9);printf("Enter Student Name:");scanf("%s",s);
        fp = fopen("uRecord.dat","rb");
        while(fread(&student,sizeof(student),1,fp)==1){
            if(strcmp(student.name,(s))==0){ //checks whether student.name is equal to s or not
                gotoxy(x,11);printf("The Student is available");
                gotoxy(x,13);printf("\xB2 ID:%d",student.id);
                gotoxy(x,14);printf("\xB2 Name:%s",student.name);
                gotoxy(x,15);printf("\xB2 Password:%s",student.pass);
                gotoxy(x,16);printf("\xB2 Mobile:%d",student.mobile);
                gotoxy(x,17);printf("\xB2 Fee:%.2f",student.fee);
                gotoxy(x,18);printf("\xB2 Age:%d ",student.age);
    
                d++;
            }
        }
        if(d==0){
    
            gotoxy(x,12);printf("\aNo Record Found");
        }
        fclose(fp);
        gotoxy(x,20);printf("Try another search?(Y/N)");
        if(getch()=='y')
            searchBy_student_Name();
        else
            lib_main_student();
    }
    
    
    int delete_student(){    //function that delete  record form Database
        system("cls");window();
        FILE *ft,*fp;
        char another;
        int d,find_student = 0;
        while(another = 'y'){  //infinite loop
            gotoxy(25,7);printf("********STUDENT DELETE********");
            gotoxy(x,9);printf("Enter the Student ID to  delete:");
            scanf("%d",&d);
            fp = fopen("uRecord.dat","rb+");
            while(fread(&student,sizeof(student),1,fp)==1){
                if(student.id==d){
                    gotoxy(x,11);printf("The student record is available");
                    gotoxy(x,13);printf("Student name is %s",student.name);
                    gotoxy(x,14);printf("AGE. is %d",student.age);
                    find_student = 1;
                    gotoxy(x,16);printf("Do you want to delete it?(Y/N):");
                    if(getch()=='y'){
                        ft=fopen("utest.dat","wb");  //temporary file for delete
                        rewind(fp);
                        while(fread(&student,sizeof(student),1,fp)==1){
                            if(student.id!=d){
                                fwrite(&student,sizeof(student),1,ft); //write all in tempory file except that
                            }                              //we want to delete
                        }
                        fclose(fp);
                        fclose(ft);
                        remove("uRecord.dat");
                        rename("utest.dat","uRecord.dat"); //copy all item from temporary file to fp except that
                                            //we want to delete
                        gotoxy(x,17);printf("The record is sucessfully deleted");
                    }
                }
            }
            if(find_student == 0){
                gotoxy(x,11);printf("No record is found");
            }
    
            gotoxy(x,18);printf("Delete another record?(Y/N)");
            if(getch()=='y'){
                delete_student();
            }
            else
                lib_main_student();
        }
    }
    
    int view_student()   //I use this function to view all student info
    {
        int j;
        system("cls");window();
        FILE *fp;
        gotoxy(5,5);printf("*********************************Student List****************************");
        gotoxy(5,6);printf(" CATEGORY    ID   STUDENT NAME    Password     MOBILE       Age       Fee");
        j=8;
        fp=fopen("uRecord.dat","rb");
        while(fread(&student,sizeof(student),1,fp)==1){
            gotoxy(5,j);printf("%s",student.cat);
            gotoxy(17,j);printf("%d",student.id);
            gotoxy(24,j);printf("%s",student.name);
            gotoxy(38,j);printf("%s",student.pass);
            gotoxy(45,j);printf("%d",student.mobile);
            gotoxy(61,j);printf("%d",student.age);
            gotoxy(71,j);printf("%.2f",student.fee);
            printf("\n\n");
            j++;
        }
        fclose(fp);
        getch();system("cls");window();
    }
    //--------------------------------------------------------------------------------------------
    
    
    //--------------------------------------Student Interface Functon---------------------------------------
    int student_pass_remove(){    //function that delete  record form Database
        system("cls"); window();
        FILE *ft,*fp;
        int d,find_student = 0;
        while(1){  //infinite loop
            gotoxy(25,7);printf("****Student Login****");
            gotoxy(x,9);printf("Enter Student ID:");
            scanf("%d",&d);
            fp = fopen("uRecord.dat","rb+");
            while(fread(&student,sizeof(student),1,fp)==1){
                if(student.id==d){
                    gotoxy(x,11);printf("The student record is available");
                    gotoxy(x,13);printf("Student name is %s",student.name);
                    gotoxy(x,14);printf("AGE. is %d",student.age);
    
                    char p[20];
                    gotoxy(x,16);printf("Enter Your Student Password:");scanf("%s",p);
                    if(strcmp(student.pass,(p))==0){
                    gotoxy(x,18); printf("Thank You");
                    getch(); student_main();
    
                    }
                    else{
                    gotoxy(x,18); printf("wrong Password");
                    getch();
                    main();
                    }
                }
            }
            if(find_student == 0){
                gotoxy(x,11);printf("No student is found");
                getch(); system("cls"); window(); main();
            }
        }
    }
    The errors I'm receiving are:

    Code:
    ||=== Build: Debug in PPCW2 (compiler: GNU GCC Compiler) ===|
    obj\Debug\main.o||In function `edit_books':|
    C:\Users\punished_snake\Documents\Uni\Semester 2\Programming Project\PPCW2\main.c|503|undefined reference to `checkid_admin'|
    obj\Debug\main.o||In function `add_student':|
    C:\Users\punished_snake\Documents\Uni\Semester 2\Programming Project\PPCW2\main.c|722|undefined reference to `getdata_student'|
    ||error: ld returned 1 exit status|
    ||=== Build failed: 3 error(s), 35 warning(s) (0 minute(s), 0 second(s)) ===|
    There's also many warnings but they're not my main concern as it stands. I just can't get my head around why I'm recieving these errors. Typically, it will be something simple I just can't spot.
    • checkid_admin - there's only two instances of this in the code. The prototype and where it appears in the warning
    • getdata_student - same applies
    • ||error: ld returned 1 exit status| - not really sure as to what this is. Not come across like an error like this before.


    If anybody could help me out with why I'm recieving these errors it would be so hugely appreciated. The project is worth 70% of the module so it's really important I get it working. Also, any advice as to how and go about making it modular would be very welcome. I realise the function prototypes are a bit of a mess right now.

    Thanks very much.
    Last edited by GeorgeIO; 04-21-2018 at 04:37 PM.

  2. #2
    Registered User
    Join Date
    May 2009
    Posts
    4,183
    Code:
    There's also many warnings but they're not my main concern as it stands. I just can't get my head around why I'm recieving these errors. Typically, it will be something simple I just can't spot.
    
        checkid_admin - there's only two instances of this in the code. The prototype and where it appears in the warning
        getdata_student - same applies
        ||error: ld returned 1 exit status| - not really sure as to what this is. Not come across like an error like this before.
    The function prototypes told the Compiler/Linker that you were going to provide those two functions. The linker is complaining that you failed to provide those two functions. To fix the problem you need to write those two functions.

    Tim S.
    "...a computer is a stupid machine with the ability to do incredibly smart things, while computer programmers are smart people with the ability to do incredibly stupid things. They are,in short, a perfect match.." Bill Bryson

  3. #3
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,659
    Did you really type in 1000 lines before pressing compile?

    Don't call main recursively.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

  4. #4
    Registered User GeorgeIO's Avatar
    Join Date
    Nov 2017
    Posts
    33
    Quote Originally Posted by Salem View Post
    Did you really type in 1000 lines before pressing compile?

    Don't call main recursively.
    No, obviously not. It turns out the errors were due to typo's. I'd missed out a couple of underscores somehow. I've been predominantly programming in Java as of late so I was using camelcase. Realising this isn't proper coding etiquate in C, I changed all the camelcase to functions with underscores (the name for this way of typing escapes me). I simply missed a couple along the way.

    And are you referring to my default switch in main? What's so bad about this? If you could provide me with an explanation and possibly suggestions on how to better it, it would be greatly appreciated.

  5. #5
    Lurking whiteflags's Avatar
    Join Date
    Apr 2006
    Location
    United States
    Posts
    9,612
    Quote Originally Posted by GeorgeIO View Post
    And are you referring to my default switch in main? What's so bad about this? If you could provide me with an explanation and possibly suggestions on how to better it, it would be greatly appreciated.
    Yes, that is one place where you call main(), but it is also not the only place. There are other places where you call main(), and those places are just as wrong because the result is recursively calling main().

    There are some (extremely) technical reasons why recursively calling main() is allowed, but consider the following:
    • now you have to manage main() like any other recursive function. Eventually you will want to stop calling main() and end the program, so what is main()'s base case?
    • most people who call main() simply want to get back to main(). In this case, calling main() is not really what you want to do.
    • If you do want to recursively call main(), a far easier solution is to roll a function like mymain(argc, argv); and recursively call that. It still needs a base case, but now you don't have to wonder about what the Standard says.


    To me it really looks like you just want to get back to main().

    You should be able to delete the calls to main() and not have to do anything else. The program isn't complicated enough to warrant any other changes.

    Why? It appears that you have a fundamental misunderstanding how program flow works. Program flow works pretty simply: when you start the program there is one main() at the base of a function call stack, and as the program executes it will call other functions like pass() and lib_main(). These other functions are stacked on top of the main().As the program continues the stack can grow higher or lower as some functions complete and others are called. However there are always occasions where there is nothing on the stack but main(), hence, program flow always goes back to main() before the program can end.

    I only glanced at the program but there really isn't a reason here to worry about getting back to main() anyway. The program flow isn't that complicated. Eventually a cooperative user will do everything that the original main() set out to do, and the user will get to make more menu choices.
    Last edited by whiteflags; 04-22-2018 at 11:40 AM.

  6. #6
    Registered User GeorgeIO's Avatar
    Join Date
    Nov 2017
    Posts
    33
    I tried deleting the calls to main() but I ran into compiler errors. How would I go about implementing a mymain(argc, argv) function? Here's an update on my program (I hope linking to github repo's are okay, since I didn't feel like pasting my code with seperate main.c and .h files would be very wise. I managed to get rid of my globals and aimed to make the program much more modular and readable. It's still got a little way to go but I'm hoping people could confirm I'm on the right lines with this. Here's the repo with my code included. Thanks.

    GitHub - bridgestrawdog/reimagined-tribble: Library Information System

  7. #7
    Lurking whiteflags's Avatar
    Join Date
    Apr 2006
    Location
    United States
    Posts
    9,612
    Well, if I got the same errors you got, then there should be a lot like this.
    Code:
    books.c: In function 'add_books':
    books.c:42:1: warning: control reaches end of non-void function [-Wreturn-type]
     }
     ^
    The solution for these is to use return statements at the end of functions, then the error should go away.

    You have basically all your functions set up to return integers:
    Code:
    /-----------Function prototypes-----------\\
    
    //Librarian Prototypes
    int lib_main(void);
    int checkid_lib(int d);
    int change_lib_pass();
    int lib_signup();
    int lib_signin();
    int lib_main_book(void);
    int lib_main_student(void);
    
    
    //Student Prototypes
    int student_pass();
    int add_student(void);
    int search_student();
    int edit_student();
    int delete_student();
    int view_student();
    int student_pass_remove();
    int student_main(void);
    int getdata_student(int choice);
    
    //Books prototypes
    int add_books(void);
    int search_books();
    int edit_books();
    int delete_books();
    int view_books();
    
    int finish();
    int pass();
    int get_password(char* pass);
    int add_window();
    int get_data(int choice);
    int checkid(int t);
    int gotoxy(int x, int y);
    int developer_info();
    int window();
    I'm not sure if you intended this or not but that means you need to always return a whole number at the end of every function.

    I have a feeling that you used 'int' as a default return type. This is bad practice... you should use void if you have nothing sensible to return to the calling function.
    Last edited by whiteflags; 04-26-2018 at 07:45 PM.

  8. #8
    Registered User GeorgeIO's Avatar
    Join Date
    Nov 2017
    Posts
    33

    Question

    So, here's an update of my program so far. I'll post the whole code here, with each .c and .h files in seperate blocks.

    main.c:

    Code:
    //Header files
    #include <stdio.h>
    #include <stdlib.h>
    #include <conio.h>
    #include <windows.h>
    #include <string.h>
    #include "librarian.h"
    #include "student.h"
    #include "books.h"
    
    int main(){
    FILE *login;
    char findBook;
    char choice;
    char password[10];
    int x = 15;
        SetConsoleTitle("Library Information System - By George Strawbridge (SC16GHS)");
        system("cls"); window();
        gotoxy(34,4);printf("Login Area");
        gotoxy(20,10);printf("1. Librarian");
        gotoxy(45,10);printf("2. Student");
        gotoxy(20,12);printf("3. Developer Info");
        gotoxy(45,12);printf("9. Exit");
        gotoxy(15,23);printf("Enter your choice: ");
        choice  = getche(); // input from keyboard
        system("cls");      //used to clear windows
        window();           // for title message
        switch(choice)
        {
        case '1':
        pass(); lib_main();
        break;
    
        case '2':
        student_pass();
        break;
    
        case '3':
        developer_info();
        break;
    
        case '9':
        finish();
        break;
    
        default :
        gotoxy(20,17);printf("Could not verify input. Please try again");
        main();
        };
        return 0;
    }
    
    COORD coord = {0,0}; ///set the cordinate to 0, 0 (top-left corner of window);
    void gotoxy(int x, int y){
        SetConsoleCursorPosition(GetStdHandle(STD_OUTPUT_HANDLE), (COORD) {x, y });
    
        return;
    }
    
    void developer_info(){       //function to show dev info
        system("cls"); window();
        gotoxy(20,6);printf("Design and Developed by....");
        gotoxy(25,8);printf("George Strawbridge");
        gotoxy(25,9);printf("School of Computing");
        gotoxy(25,10);printf("University of Leeds");
        getch(); main();
    
        return;
    }
    
    void window(){
        gotoxy(15,1); printf("*****Library Information System*****");
        gotoxy(5,2);printf("________________________________________________________");
    
        return 0;
     }
    
    
    void finish(){          // function to Exit Message
        char choice;
        int x = 15;
        system("cls"); window();
        gotoxy(16,11);printf("Are you sure want to exit? (Y/N): ");
        choice  = getche();
        if(choice == 'n' || choice == 'N'){
        system("cls"); window(); main();
        }
        else{
        system("cls"); window();
        gotoxy(33,11);printf("Thank You");
        gotoxy(33,12);printf("School of Computing");
        gotoxy(x,21);printf("Exiting in 3 second...........>");
        Sleep(3000);
        exit(0);
        }
        return 0;
    }
    books.c:

    Code:
    #include <stdio.h>
    #include <stdlib.h>
    #include <conio.h>
    #include <windows.h>
    #include "structs.h"
    #include "main.h"
    #include "books.h"
    #include "librarian.h"
    
    const char *CATEGORIES[]={ "Computing", "Electronics", "Electrical", "Engineering", "Mechanical", "Architecture"};
    const int CATEGORIES_SIZE = sizeof(CATEGORIES) / sizeof(*CATEGORIES);
    
    
    int add_books(void){    //funtion for adding books
        system("cls");window();
        FILE *fp;
        int x = 15, choice;
        system("cls"); window(); add_category();
        gotoxy(x,19); printf("Enter your choice:");
        scanf("%d", &choice);
        if(choice==7)
            lib_main_book() ;
        system("cls"); window();
        fp = fopen("Record.dat","ab+");
        if(get_data(choice) == 1){
            book.cat=CATEGORIES[choice-1];
            fseek(fp,0,SEEK_END);
            fwrite(&book,sizeof(book),1,fp);
            fclose(fp);
            gotoxy(x,17);printf("The record is sucessfully saved");
            gotoxy(x,19);printf("Save any more?(Y / N):");
            if(getch()=='n'){
                system("cls"); lib_main_book();
            }else{
                add_books();
            }
        }
        fclose(fp);
    
        return 0;
    }
    
    int add_category(){      //Function for Books Catagory Interface
        system("cls"); window();
        gotoxy(25,6);printf("******SELECT CATEGORIES******");
        gotoxy(25,9);printf("1. Computer");
        gotoxy(25,10);printf("2. Electronics");
        gotoxy(25,11);printf("3. Electrical");
        gotoxy(25,12);printf("4. Civil");
        gotoxy(25,13);printf("5. Mechanical");
        gotoxy(25,14);printf("6. Architecture");
        gotoxy(25,16);printf("7. Back");
    
        return 0;
    }
    
    int get_data(int choice){
        int x = 15;
        int x1 = 30; int bookID;
        gotoxy(x,7);printf("Enter the Information Bellow");
        gotoxy(x,9);printf("Category:");  gotoxy(x1,9);printf("%s",CATEGORIES[choice-1]);
        gotoxy(x,10);printf("Book ID:");  gotoxy(x1,10);scanf("%d",&bookID);
    
         if(book.id==bookID){
                    gotoxy(x,11);printf("Id is already Exits");
                    getch(); add_books();
                    }
    
        book.id=bookID;
        gotoxy(x,11);printf("Book Name:"); gotoxy(x1,11);scanf("%s",book.name);
        gotoxy(x,12);printf("Author:");    gotoxy(x1,12);scanf("%s",book.Author);
        gotoxy(x,13);printf("Quantity:");  gotoxy(x1,13);scanf("%d",&book.quantity);
        gotoxy(x,14);printf("Price:");     gotoxy(x1,14);scanf("%f",&book.Price);
        gotoxy(x,15);printf("Rack No:");   gotoxy(x1,15);scanf("%d",&book.racknumber);
        return 1;
    }
    
    int check_id(int t)      //Function to check ID is exist or not
    {
        FILE *temp;
        temp = fopen("Record.dat","rb+");
        while(fread(&book,sizeof(book),1,temp)==1)
            if(book.id == t){
                fclose(temp);
                return 0;
            }
            fclose(temp);
            return 1;
    
    }
    
    int edit_books()       //Function to Edit Books info
    {
        int x = 15;
        system("cls");window();
        FILE *fp;
        int c=0,d;
        gotoxy(27,6);printf("****Edit Book Section****");
        while(1)
        {
            gotoxy(x,8);printf("Enter Book Id to edit:");scanf("%d",&d);
            fp=fopen("uRecord.dat","rb+");
            while(fread(&book,sizeof(book),1,fp)==1)
            {
                if(check_id(d)==0)
                {
                    gotoxy(x,9);printf("The book is availble");
                    gotoxy(x,10);printf("The Book ID:%d",book.id);
                    gotoxy(x,11);printf("New name:");scanf("%s",book.name);
                    gotoxy(x,12);printf("New Author:");scanf("%s",book.Author);
                    gotoxy(x,13);printf("New quantity:");scanf("%d",&book.quantity);
                    gotoxy(x,14);printf("New price:");scanf("%f",&book.Price);
                    gotoxy(x,15);printf("New rackno:");scanf("%d",&book.racknumber);
                    gotoxy(x,16);printf("The record is modified");
                    fseek(fp,ftell(fp)-sizeof(book),0);
                    fwrite(&book,sizeof(book),1,fp);
                    fclose(fp);
                    c=1;
                }
                if(c==0)
                {
                    gotoxy(x,11);printf("No record found");
                }
            }
    
        gotoxy(x,18);printf("Modify another Record?(Y/N)");
        if(getch()=='y'){
            edit_books();
        }
        else
            lib_main_student();
        }
    }
    
    int search_books(){    //Function to search books
        system("cls"); window();
        gotoxy(25,7);printf("********Search Books********");
        gotoxy(25,10);printf("1. Search By ID");
        gotoxy(25,12);printf("2. Search By Name");
        gotoxy(25,16);printf("Enter Your Choice: ");
        switch(getch())
        {
            case '1':
                search_ID();
                break;
            case '2':
                search_name();
                break;
            default :
                getch();search_books();
        }
        return 0;
    }
    
    int search_ID(){      //Function to search books by given ID
        system("cls"); window();
        int id, x = 20; FILE *fp;
        gotoxy(25,7);printf("*****Search Books By Id*****");
        gotoxy(25,9);printf("Enter the book id:");scanf("%d",&id);
        int findBook = 0;
        fp = fopen("Record.dat","rb");
        while(fread(&book,sizeof(book),1,fp)==1){
            if(book.id==id){
                Sleep(2);
                gotoxy(x,11);printf("The Book is available");
                gotoxy(x,13);printf("ID:%d",book.id);
                gotoxy(x,14);printf("Name:%s",book.name);
                gotoxy(x,15);printf("Author:%s ",book.Author);
                gotoxy(x,16);printf("Qantity:%d ",book.quantity);
                gotoxy(x,17);printf("Price:%.2f",book.Price);
                gotoxy(x,18);printf("Rack No:%d ",book.racknumber);
                findBook = 1;
            }
        }
        if(findBook == 0){  //checks whether conditiion enters inside loop or not
            gotoxy(x,12);printf("\aNo Record Found");
        }
        fclose(fp);
        gotoxy(x,20);printf("Try another search?(Y/N)");
        if(getch()=='y')
            search_ID();
        else
        system("cls");window();
    
        return 0;
    }
    
    int search_name(){    //Function to search books by using Books name
        system("cls");window();
        char s[15];
        int d=0;
        FILE *fp;
        gotoxy(25,7);printf("****Search Books By Name****");
        gotoxy(25,9);printf("Enter Book Name:");scanf("%s",s);
        fp = fopen("Record.dat","rb");
        while(fread(&book,sizeof(book),1,fp)==1){
            if(strcmp(book.name,(s))==0){ //checks whether book.name is equal to s or not
                gotoxy(27,11);printf("The Book is available");
                gotoxy(27,13);printf("ID:%d",book.id);
                gotoxy(27,14);printf("Name:%s",book.name);
                gotoxy(27,15);printf("Author:%s",book.Author);
                gotoxy(27,16);printf("Quantity:%d",book.quantity);
                gotoxy(27,17);printf("Price:Rs.%.2f",book.Price);
                gotoxy(27,18);printf("Rack No:%d ",book.racknumber);
                d++;
            }
        }
        if(d==0){
            gotoxy(25,12);printf("\aNo Record Found");
        }
        fclose(fp);
        gotoxy(25,20);printf("Try another search?(Y/N)");
        if(getch()=='y')
        search_name();
        else
        system("cls");window();
    
        return 0;
    }
    
    int delete_books(){    //function that delete  record form Database
        system("cls"); window();
        FILE *ft,*fp;
        char another;
        int d, x = 15, findBook = 0;
        while(another = 'y'){  //infinite loop
            gotoxy(25,7);printf("********BOOK DELETE********");
            gotoxy(x,9);printf("Enter the Book ID to  delete:"); scanf("%d",&d);
            fp = fopen("Record.dat","rb+");
            while(fread(&book,sizeof(book),1,fp)==1){
                if(book.id==d){
                    gotoxy(x,11);printf("The book record is available");
                    gotoxy(x,13);printf("Book name is %s",book.name);
                    gotoxy(x,14);printf("Rack No. is %d",book.racknumber);
                    findBook = 1;
                    gotoxy(x,16);printf("Do you want to delete it?(Y/N):");
                    if(getch()=='y'){
                        ft=fopen("test.dat","wb");  //temporary file for delete
                        rewind(fp);
                        while(fread(&book,sizeof(book),1,fp)==1){
                            if(book.id!=d){
                                fwrite(&book,sizeof(book),1,ft); //write all in tempory file except that
                            }                              //we want to delete
                        }
                        fclose(fp);
                        fclose(ft);
                        remove("Record.dat");
                        rename("test.dat","Record.dat"); //copy all item from temporary file to fp except that
                                            //we want to delete
                        gotoxy(x,17);printf("The record is sucessfully deleted");
                    }
                }
            }
            if(findBook == 0){
                gotoxy(x,11);printf("No record is found");
            }
    
            gotoxy(x,18);printf("Delete another record?(Y/N)");
            if(getch()=='y'){
                delete_books();
            }
            else
                lib_main_book();
        }
        return 0;
    }
    
    int view_books()   //I use this function to view all books info
    {
        int j;
        system("cls");window();
        FILE *fp;
        gotoxy(5,5);printf("*********************************Book List****************************");
        gotoxy(5,6);printf(" CATEGORY      ID      BOOK NAME       AUTHOR     QTY   PRICE   RACK NUMBER");
        j=8;
        fp=fopen("Record.dat","rb");
        while(fread(&book,sizeof(book),1,fp)==1){
            gotoxy(5,j);printf("%s",book.cat);
            gotoxy(19,j);printf("%d",book.id);
            gotoxy(27,j);printf("%s",book.name);
            gotoxy(44,j);printf("%s",book.Author);
            gotoxy(56,j);printf("%d",book.quantity);
            gotoxy(61,j);printf("%.2f",book.Price);
            gotoxy(71,j);printf("%d",book.racknumber);
            printf("\n\n");
            j++;
        }
        fclose(fp);
        getch(); system("cls"); window();
    
        return 0;
    }
    
    int add_window_u(){      //Function for Student Catagory Interface
        int x = 15;
        system("cls"); window();
        gotoxy(25,6);printf("******SELECT CATEGOIES******");
        gotoxy(x,9);printf("1. Student");
        gotoxy(x,11);printf("2. Admin");
        gotoxy(x,15);printf("7. Back");
    
        return 0;
    }
    librarian.c:

    Code:
    #include <stdio.h>
    #include <stdlib.h>
    #include <conio.h>
    #include <string.h>
    #include <windows.h>
    #include "main.h"
    #include "librarian.h"
    #include "books.h"
    #include "student.h"
    
    int lib_main(void){
        char choice;
        system("cls"); window();
        gotoxy(32,4);printf("Librarian Workspace");
        gotoxy(15,10);printf("1. Book Info");
        gotoxy(35,10);printf("2. Student Info");
        gotoxy(15,12);printf("3. Student Password");
        gotoxy(55,10);printf("8. Back");
        gotoxy(55,12);printf("9. Exit");
        gotoxy(15,23);printf("Enter your choice: ");
        choice  = getche();
    
        switch(choice)
        {
        case '1':
        lib_main_book();
        break;
    
        case '2':
        lib_main_student();
        break;
    
        case '3':
        change_lib_pass();
        break;
    
        case '8':
        main();
        break;
    
        case '9':
        finish();
        break;
    
        default :
        lib_main();
        };
    
        return 0;
    }
    
    int lib_main_book(void){
        int x = 15;
        char choice;
        while(1){
        system("cls"); window();
            gotoxy(35,4);printf("Librarian Area");
            gotoxy(x,6);printf("1. Add Book");
            gotoxy(x,8);printf("2. Search Book");
            gotoxy(x,10);printf("3. Modify Book Record");
            gotoxy(x,12);printf("4. Delete Book Record");
            gotoxy(x,14);printf("5. View book list");
            gotoxy(x,20);printf("8. Back");
            gotoxy(25,20);printf("9. Exit");
            gotoxy(x,23);printf("Enter your choice: ");
            choice  = getche();
    
            switch(choice){
                case '1':
                    add_books();
                    break;
                case '2':
                    search_books();
                    break;
                case '3':
                    edit_books();
                    break;
                case '4':
                    delete_books();
                    break;
                case '5':
                    view_books();
                    break;
                case '8':
                    system("cls"); lib_main();
                    break;
                case '9':
                    finish();
                    break;
                default:
                    break;
            };
        };
    }
    
    int lib_main_student(void){
        int x = 15;
        char choice;
        while(1){
        system("cls"); window();
            gotoxy(35,4);printf("Librarian Area");
            gotoxy(x,6);printf("1. Add Student");
            gotoxy(x,8);printf("2. Search Student");
            gotoxy(x,10);printf("3. Modify Student Record");
            gotoxy(x,12);printf("4. Delete Student Record");
            gotoxy(x,14);printf("5. View All Students");
            gotoxy(x,20);printf("8. Back");
            gotoxy(25,20);printf("9. Exit");
            gotoxy(x,23);printf("Enter your choice: ");
            choice  = getche();
            switch(choice){
                case '1':
                    add_student();
                    break;
                case '2':
                    search_student();
                    break;
                case '3':
                    edit_student();
                    break;
                case '4':
                    delete_student();
                    break;
                case '5':
                    view_student();
                    break;
                case '8':
                    lib_main();
                    break;
                case '9':
                    finish();
                    break;
                default:
                    break;
            };
        };
    }
    
    
    
    int change_lib_pass(){    // function for librarian Password change
        char password[10];
        system("cls"); window();
        FILE *login;
        char old_pass[10], new_pass[10];
        gotoxy(15,10);printf("Enter Old password: ");
        get_password(old_pass);
        gotoxy(15,12);printf("Enter New password: ");
        get_password(new_pass);
        login = fopen("password.dat","rb+");
        while(fread(&password,sizeof(password),1,login)==1){
            if(strcmp(old_pass,password)==0){
                strcpy(password,new_pass);
                fseek(login,-sizeof(password),SEEK_CUR);
                fwrite(&password,sizeof(password),1,login);
                fclose(login);
                gotoxy(15,15);printf("Password sucessfully changed! ");
            }else{
                gotoxy(15,15);printf("Password changing process failed!");
            }
        }
        gotoxy(15,23);printf("press any key to go back..");
        getch(); system("cls"); window(); lib_main();
    
        return 0;
    }
    
    int lib_signup(){   //Librarian sign up function
        FILE *login;
        int x = 15;
        char username[15];
        char password[10];
        char temp[10];
        login = fopen("username.dat","wb");
        login = fopen("password.dat","wb");
        gotoxy(x,10);printf("Choose a user name: ");
        get_username(username);
        gotoxy(x,11);printf("Enter password: ");
        get_password(password);
        gotoxy(x,12);printf("Re Enter Password: ");
        get_password(temp);
        while(strcmp(password,temp)!=0){
            gotoxy(x,10);printf("Password did not matched! Enter again");
            gotoxy(x,11);printf("Enter password: ");
            get_password(password);
            gotoxy(x,12);printf("Re Enter Password: ");
            get_password(temp);
            system("cls");
        }
        fwrite(&username,sizeof(username),1,login);
        fwrite(&password,sizeof(password),1,login);
        fclose(login);
        system("cls"); window();
    
        return 0;
    }
    
    
    int lib_signin(){     // function for librarian Login part
        FILE *login;
        int x = 15;
        char password[10];
        char username[25];
        char temp[10];
        login = fopen("password.dat","rb");
        login = fopen("username.dat","rb");
        gotoxy(x,10);printf("Enter User Name: ");
        get_username(temp);
        gotoxy(x,11);printf("Enter password: ");
        get_password(temp);
    
        while(fread(&username, sizeof(username),1,login)==1){
            while(strcmp(temp,username)!=0){
                system("cls"); window();
                gotoxy(x,10); printf("User Name didn't match! Please try again: ");
                get_username(temp);
            }
            gotoxy(x,12);printf("Username Match");
            break;{
    
        while(fread(&password, sizeof(password),1,login)==1){
            while(strcmp(temp,password)!=0){
                system("cls"); window();
                gotoxy(x,10); printf("Password did not match!---Enter Again: ");
                get_password(temp);
            }
            gotoxy(x,12);printf("Password Match");
            break;
        }
        fclose(login);
        Sleep(1000);
        system("cls");window();
    }
        }
        return 0;
    }
    
    int pass(){            // Librarian password function
        FILE *login;
        login = fopen("password.dat","rb");
        if(login == NULL){
            gotoxy(10,9);printf("Unable to find librarian info in database. Sign up to become a librarian now.");
            lib_signup();
        }else{
            lib_signin();
        }
        return 0;
    }
    
    int lib_pass(){            // Librarian username function
        FILE *login;
        login = fopen("username.dat","rb");
        if(login == NULL){
            gotoxy(10,9);printf("Unable to find librarian info in database. Sign up to become a librarian now.");
            lib_signup();
        }else{
            lib_signin();
        }
        return 0;
    }
    
    int get_password(char* pass){  // function for Password
        char temp_pass[25];
        int i=0;
         while(1)
        {
                temp_pass[i]=getch();
                if(temp_pass[i]==13){break;}
                else if(temp_pass[i]==8)
                {
                    if(i!=0) {
                    printf("\b \b");
                    i--;
                    } else {printf("\a");}
                }
                else
                {
                    printf("*");
                    *(pass+i) = temp_pass[i];
                    i++;
                }
                 *(pass+i)='\0';
         }
         return 0;
    }
    
    int get_username(char* username){  // function for username
        char temp_username[25];
        int i=0;
         while(1)
        {
                temp_username[i]=getch();
                if(temp_username[i]==13){break;}
                else if(temp_username[i]==8)
                {
                    if(i!=0) {
                    printf("\b \b");
                    i--;
                    } else {printf("\a");}
                }
                else
                {
                temp_username[i] = getchar();
                putchar (temp_username[i]);}
                    *(username+i) = temp_username[i];
                    i++;
    
                 *(username+i)='\0';
         }
         return 0;
    }
    student.c:

    Code:
    //Header (FILE is defined in stdio.h)
    #include <stdio.h>
    #include "structs.h"
    
    int student_main(void){
        char choice;
        int x = 15;
        while(1){
            system("cls"); window();
            gotoxy(35,4);printf("You are logged in as a student");
            gotoxy(x,6);printf("1. View Book List");
            gotoxy(x,8);printf("2. Search Book");
            gotoxy(x,10);printf("3. View All Student info");
            gotoxy(x,20);printf("8. Back");
            gotoxy(25,20);printf("9. Exit");
            gotoxy(x,23);printf("Enter your choice: ");
            choice  = getche();
    
            switch(choice){
                case '1':
                    view_books();
                    break;
                case '2':
                    search_books();
                    break;
                case '3':
                    view_student();
                    break;
                case '8':
                    system("cls");
                    main();
                    break;
                case '9':
                    finish();
                    break;
                default:
                    main();
                    break;
            };
        };
    }
    
    int student_pass(){          // function for student Password
        system("cls"); window();
        gotoxy(15,7);printf("To Enter the Library you need a pass");
        gotoxy(15,9);printf("Do you have a library pass?(Y/N): ");
        if(getch()=='n'){
        gotoxy(15,10);printf("Please contact the librarian to sign up if you don't have a pass");
        getch(); system("cls"); window(); main();
        }
        else
        {
        student_pass_remove();
        }
        return 0;
    }
    
    
    char catagories_u[][15]={"Student","Teacher","Others"};
    
    int add_student(void){    //funtion for adding student
        FILE *fp;
        int i, choice, x = 15;
        system("cls");window();
        lib_main_student();
        system("cls");window();
        fp = fopen("uRecord.dat","ab+");
        if(get_data_student(choice) == 1){
            student.cat=catagories_u[choice-1];
            fseek(fp,0,SEEK_END);
            fwrite(&student,sizeof(student),1,fp);
            fclose(fp);
            gotoxy(x,17);printf("The record is sucessfully saved");
            gotoxy(x,19);printf("Save any more?(Y / N):");
            if(getch()=='n'){
                system("cls"); window(); lib_main_student();
            }else{
                add_student();
            }
        }
        fclose(fp);
    }
    
    int get_data_student(int choice)
    {
        int x = 15;
        int x1 = 30;
        int studentID;
        gotoxy(x,7);printf("Enter the Information Below");
        gotoxy(x,9);printf("Category:");  gotoxy(x1,9);printf("%s",catagories_u[choice-1]);
        gotoxy(x,10);printf("Student ID:");  gotoxy(x1,10);scanf("%d",&studentID);
    
                if(student.id==studentID){
                    gotoxy(x,11);printf("Id is already Exits");
                    getch(); add_student;
                    }
    
        student.id=studentID;
        gotoxy(x,11);printf("Student Name:");  gotoxy(x1,11);scanf("%s",&student.name);
        gotoxy(x,12);printf("Password:");gotoxy(x1,12);scanf("%s",&student.pass);
        gotoxy(x,13);printf("Mobile:");     gotoxy(x1,13);scanf("%d",&student.mobile);
        gotoxy(x,14);printf("Fee:");        gotoxy(x1,14);scanf("%f",&student.fee);
        gotoxy(x,15);printf("Age:");        gotoxy(x1,15);scanf("%d",&student.age);
        return 1;
    }
    
    int checkid_student(int t)      //Function to check ID is exist or not
    {
        FILE *temp;
        temp = fopen("uRecord.dat","rb+");
        while(fread(&student,sizeof(student),1,temp)==1)
            if(student.id == t){
                fclose(temp);
                return 0;
            }
            fclose(temp);
            return 1;
    
    }
    
    int edit_student()       //Function to Edit student info
    {
        int x = 15;
        system("cls");window();
        FILE *fp;
        int c=0,d;
        gotoxy(27,6);printf("****Edit Student Section****");
        while(1)
        {
            gotoxy(x,8);printf("Enter Librarian Id to edit:");scanf("%d",&d);
            fp=fopen("uRecord.dat","rb+");
            while(fread(&student,sizeof(student),1,fp)==1)
            {
                if(checkid_student(d)==0)
                {
                    gotoxy(x,9);printf("The Librarian is availble");
                    gotoxy(x,10);printf("The Librarian ID:%d",student.id);
                    gotoxy(x,11);printf("New Name:");scanf("%s",student.name);
                    gotoxy(x,12);printf("Password:");scanf("%s",student.pass);
                    gotoxy(x,13);printf("New Mobile:");scanf("%d",&student.mobile);
                    gotoxy(x,14);printf("New Fee:");scanf("%f",&student.fee);
                    gotoxy(x,15);printf("New Age:");scanf("%d",&student.age);
                    gotoxy(x,16);printf("The record is modified");
                    fseek(fp,ftell(fp)-sizeof(student),0);
                    fwrite(&student,sizeof(student),1,fp);
                    fclose(fp);
                    c=1;
                }
                if(c==0)
                {
                    gotoxy(x,11);printf("No record found");
                }
            }
    
        gotoxy(x,18);printf("Modify another Record?(Y/N)");
        if(getch()=='y'){
            edit_student();
        }
        else
            lib_main_student();
        }
    }
    
    int search_student(){    //Function to search student
        int x = 15;
        system("cls");window();
        gotoxy(27,7);printf("******Search Student******");
        gotoxy(x,10);printf("1. Search By ID");
        gotoxy(x,12);printf("2. Search By Name");
        gotoxy(x,14);printf("Enter Your Choice: ");
        switch(getch())
        {
            case '1':
                searchBy_student_ID();
                break;
            case '2':
                searchBy_student_Name();
                break;
            default :
                getch(); search_student();
        }
    }
    
    int searchBy_student_ID(){      //Function to search Student by given ID
        system("cls");window();
        int x = 15;
        int id; FILE *fp;
        gotoxy(27,7);printf("****Search Student By Id****");
        gotoxy(x,9);printf("Enter student id:");scanf("%d",&id);
        int find_student = 0;
        fp = fopen("studentRecord.dat","rb");
        while(fread(&student,sizeof(student),1,fp)==1){
            if(student.id==id){
                Sleep(2);
                gotoxy(x,11);printf("The student is available");
                gotoxy(x,13);printf("ID:%d",student.id);
                gotoxy(x,14);printf("\Name:%s",student.name);
                gotoxy(x,15);printf("Password:%s ",student.pass);
                gotoxy(x,16);printf("Mobile:%d ",student.mobile);
                gotoxy(x,17);printf("Fee:%.2f",student.fee);
                gotoxy(x,18);printf("Age:%d ",student.age);
    
                find_student = 1;
            }
        }
        if(find_student == 0){  //checks if condition enters loop
            gotoxy(x,12);printf("No Record Found");
        }
        fclose(fp);
        gotoxy(x,20);printf("Try another search?(Y/N)");
        if(getch()=='y')
            searchBy_student_ID();
        else
            lib_main_student();
    }
    
    int searchBy_student_Name(){    //Function to search student by using Books name
        system("cls");window();
        int x = 15;
        char s[15];
        int d=0;
        FILE *fp;
        gotoxy(27,7);printf("****Search Student By Name****");
        gotoxy(x,9);printf("Enter Student Name:");scanf("%s",s);
        fp = fopen("uRecord.dat","rb");
        while(fread(&student,sizeof(student),1,fp)==1){
            if(strcmp(student.name,(s))==0){ //checks whether student.name is equal to s or not
                gotoxy(x,11);printf("The Student is available");
                gotoxy(x,13);printf("\xB2 ID:%d",student.id);
                gotoxy(x,14);printf("\xB2 Name:%s",student.name);
                gotoxy(x,15);printf("\xB2 Password:%s",student.pass);
                gotoxy(x,16);printf("\xB2 Mobile:%d",student.mobile);
                gotoxy(x,17);printf("\xB2 Fee:%.2f",student.fee);
                gotoxy(x,18);printf("\xB2 Age:%d ",student.age);
    
                d++;
            }
        }
        if(d==0){
    
            gotoxy(x,12);printf("\aNo Record Found");
        }
        fclose(fp);
        gotoxy(x,20);printf("Try another search?(Y/N)");
        if(getch()=='y')
            searchBy_student_Name();
        else
            lib_main_student();
    }
    
    int delete_student(){    //function that delete  record form Database
        system("cls");window();
        FILE *ft,*fp;
        char another;
        int x = 15;
        int d,find_student = 0;
        while(another = 'y'){  //infinite loop
            gotoxy(25,7);printf("********STUDENT DELETE********");
            gotoxy(x,9);printf("Enter the Student ID to  delete:");
            scanf("%d",&d);
            fp = fopen("uRecord.dat","rb+");
            while(fread(&student,sizeof(student),1,fp)==1){
                if(student.id==d){
                    gotoxy(x,11);printf("The student record is available");
                    gotoxy(x,13);printf("Student name is %s",student.name);
                    gotoxy(x,14);printf("AGE. is %d",student.age);
                    find_student = 1;
                    gotoxy(x,16);printf("Do you want to delete it?(Y/N):");
                    if(getch()=='y'){
                        ft=fopen("utest.dat","wb");  //temporary file for delete
                        rewind(fp);
                        while(fread(&student,sizeof(student),1,fp)==1){
                            if(student.id!=d){
                                fwrite(&student,sizeof(student),1,ft); //write all in tempory file except that
                            }                              //we want to delete
                        }
                        fclose(fp);
                        fclose(ft);
                        remove("uRecord.dat");
                        rename("utest.dat","uRecord.dat"); //copy all item from temporary file to fp except that
                                            //we want to delete
                        gotoxy(x,17);printf("The record is sucessfully deleted");
                    }
                }
            }
            if(find_student == 0){
                gotoxy(x,11);printf("No record is found");
            }
    
            gotoxy(x,18);printf("Delete another record?(Y/N)");
            if(getch()=='y'){
                delete_student();
            }
            else
                lib_main_student();
        }
    }
    
    int view_student()   //I use this function to view all student info
    {
        int j;
        system("cls");window();
        FILE *fp;
        gotoxy(5,5);printf("*********************************Student List****************************");
        gotoxy(5,6);printf(" CATEGORY    ID   STUDENT NAME    Password     MOBILE       Age       Fee");
        j=8;
        fp=fopen("uRecord.dat","rb");
        while(fread(&student,sizeof(student),1,fp)==1){
            gotoxy(5,j);printf("%s",student.cat);
            gotoxy(17,j);printf("%d",student.id);
            gotoxy(24,j);printf("%s",student.name);
            gotoxy(38,j);printf("%s",student.pass);
            gotoxy(45,j);printf("%d",student.mobile);
            gotoxy(61,j);printf("%d",student.age);
            gotoxy(71,j);printf("%.2f",student.fee);
            printf("\n\n");
            j++;
        }
        fclose(fp);
        getch();system("cls");window();
    }
    //--------------------------------------------------------------------------------------------
    
    //--------------------------------------Student Interface Functon---------------------------------------
    int student_pass_remove(){    //function that delete  record form Database
        system("cls"); window();
        FILE *ft,*fp;
        int d,find_student = 0;
        int x = 15;
        while(1){  //infinite loop
            gotoxy(25,7);printf("****Student Login****");
            gotoxy(x,9);printf("Enter Student ID:");
            scanf("%d",&d);
            fp = fopen("uRecord.dat","rb+");
            while(fread(&student,sizeof(student),1,fp)==1){
                if(student.id==d){
                    gotoxy(x,11);printf("The student record is available");
                    gotoxy(x,13);printf("Student name is %s",student.name);
                    gotoxy(x,14);printf("AGE. is %d",student.age);
    
                    char p[20];
                    gotoxy(x,16);printf("Enter Your Student Password:");scanf("%s",p);
                    if(strcmp(student.pass,(p))==0){
                    gotoxy(x,18); printf("Thank You");
                    getch(); student_main();
    
                    }
                    else{
                    gotoxy(x,18); printf("wrong Password");
                    getch();
                    main();
                    }
                }
            }
            if(find_student == 0){
                gotoxy(x,11);printf("No student is found");
                getch(); system("cls"); window(); main();
            }
        }
    }
    books.h:

    Code:
    //Books prototypes
    int add_books(void);
    int search_books();
    int edit_books();
    int delete_books();
    int view_books();
    int add_category();
    int get_data(int choice);
    int check_id(int t);
    int search_ID();
    int search_name();
    Code:
    //Librarian Prototypes
    int lib_main(void);
    int checkid_lib(int d);
    int change_lib_pass();
    int get_username(char* username);
    int lib_signup();
    int lib_signin();
    int lib_main_book(void);
    int lib_main_student(void);
    int add_student(void);
    int get_password(char* pass);
    int get_username(char* username);
    main.h:

    Code:
    //Main prototypes
    int gotoxy(int x, int y);
    int developer_info();
    int window();
    int get_password(char* pass);
    int finish();
    int main();
    student.h:

    Code:
    //Student prototypes
    int student_pass();
    int search_student();
    int edit_student();
    int delete_student();
    int view_student();
    int student_pass_remove();
    int student_main(void);
    int getdata_student(int choice);
    int checkid_student(int t);
    int search_by_student_ID();
    structs.h

    Code:
    struct STUDENT             //Structure variable for student
    {
        int id;
        char name[20];
        char pass[20];
        int mobile;
        float fee;
        int age;
        char *cat;
    };
    struct STUDENT student;
    
    struct BOOK             //Structure variable for BOOK
    {
        int id;
        char name[20];
        char Author[20];
        int quantity;
        float Price;
        int racknumber;
        char *cat;
    };
    struct BOOK book;

    Now, whiteflags...I know most of these functions should be void, but I spoke to my tutor and he said using int as a default value is fine as long as I return 0; at the end of each function. I'm guessing this is probably bad practice, but since I'm now getting no warnings, would I be able to remove the calls to main without loosing any of my program functionality?

    The one and only warning I am getting is:

    Code:
    ||Warning: resolving _Sleep by linking to _Sleep@4|
    Now, I have no idea what this is saying. Even a google search didn't seem to bring anything up about it. Any ideas? Also if you run the program, and choose option 1 (Librarian) it will ask you to create an account. When entering the username, the program prints out the first letter of whatever username chosen. Any ideas? I tried messing around with the relevant functions but couldn't fix the error.

    I'm also planning on creating a helper function to replace the amount of times I use 'gotoxy; printf;'. I've never made a helper function before so any advice would be greatly appreciated.

    Thanks guys and gals.

  9. #9
    Registered User
    Join Date
    Dec 2017
    Posts
    1,628
    It's better to control your main loop by returning instead of by recursively calling main. It's an easy fix. Save a copy of your program and fix it up, then test it.

    You do so many:
    Code:
        gotoxy(15,23);printf("Value: %d", 12345)
    It would be nice to be able to do this:
    Code:
    #include <stdarg.h>
    void xyprintf(int x, int y, const char *fmt, ...) {
        va_list va;
        va_start(va, fmt);
        gotoxy(x, y);
        vprintf(fmt, va);
        va_end(va);
    }
    
    void f() {
        // call it like this
        xyprintf(15, 23, "Value: %d", 12345);
    }
    As for the warning, you need to include <windows.h> in student.c.

    A little inaccuracy saves tons of explanation. - H.H. Munro

  10. #10
    Registered User
    Join Date
    May 2010
    Posts
    4,632
    As already noted you should never call main() (by any function, especially recursively) and the function main() requires no prototype.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Getting system information
    By DimensionX in forum C Programming
    Replies: 3
    Last Post: 10-09-2009, 12:12 PM
  2. C Library For Filesystem information?
    By Newmer60 in forum C Programming
    Replies: 2
    Last Post: 06-27-2008, 11:12 AM
  3. System Information in C++
    By 333 in forum C++ Programming
    Replies: 1
    Last Post: 06-08-2008, 03:04 AM
  4. System information.
    By X3no in forum C++ Programming
    Replies: 10
    Last Post: 09-19-2007, 04:49 PM
  5. system information ?
    By djarian in forum Windows Programming
    Replies: 1
    Last Post: 12-18-2003, 07:54 AM

Tags for this Thread