IELTS Exam Registration Programing In c With Database

IELTS Exam Registration Programing In c With Database

#include <stdio.h>
#include <stdlib.h>
#include <time.h>

void registration ();
void reginfo();
void adminpanel();
void search();
void update();
void deletefile();

struct registration
{
    char name[30];
    int  age;
    char address[30];
    int  number;
    char regnum [30];
    char medium[30];
    char type[30];
    char area[30];
} reg;





void adminpanel()
{
    int c, emp,ex;
//do
//{
    system("cls");
    char pass[10],password[10]="Hamza";
f:
    printf("\n\n\t\tEnter the password to login:");
    scanf("%s",pass);

    if (strcmp(pass,password)==0)
    {
        system("cls");

        printf("\n\nPassword Match!\nLOADING");
        printf("\n\t---Select your choice---------\n");
        printf("\n\t1. SEARCH\n\t2. DELETE\n\t3. UPDATE");
        printf("\n\t4. SORT\n\t5. EXIT\n");
        printf("\n\n--------------------------------------------------------------\n");

        printf("\nEnter your choice:");

        scanf("%d", &c);
        printf("\n");
        switch (c)
        {
        case 1:
            search();
            break;
        case 2:
            deletefile();
            break;
        case 3:
            update();
            break;
        case 4:
            emp = empty();
            if (emp == 0)
                printf("\n The file is EMPTY\n");
            else
                sort();
            break;
        case 5:
            exit(1);
            break;
        default:
            printf("\nYour choice is wrong\nPlease try again...\n");
            break;

        }
    }
    else
    {
        printf("\n\nWrong password!!\a\a\a");
login_try:
        printf("\nEnter 1 to try again and 0 to exit:");
        scanf("%d",&ex);
        if (ex==1)
        {

            system("cls");
            goto f;
        }

        else if (exit==0)
        {
            system("cls");
            close();
        }
        else
        {
            printf("\nInvalid!");

            system("cls");
            adminpanel();
        }



    }




// }while (c != 6);
}


int empty()
{
    int c = 0;
    FILE *fp;
    fp = fopen("Record", "r");
    while (fread(&reg, sizeof(reg), 1, fp))
        c = 1;
    fclose(fp);
    return c;
}

void update()
{
    int avl;
    FILE *fpt;
    FILE *fpo;
    int s, r, ch;
    printf("Enter Number to update:");
    scanf("%d", &r);
    avl = avlnumber(r);
    if (avl == 0)
    {
        printf("Number %d is not Available in the file", r);
    }
    else
    {
        fpo = fopen("Record", "r");
        fpt = fopen("TempFile", "w");
        while (fread(&reg, sizeof(reg), 1, fpo))
        {
            s = reg.number;
            if (s != r)
                fwrite(&reg, sizeof(reg), 1, fpt);
            else
            {
                printf("\n\t1. Update Name of Number %d", r);
                printf("\n\t2. Update Number %d", r);
                printf("\n\t3. Update both Name and Number %d", r);
                printf("\nEnter your choice:");
                scanf("%d", &ch);
                switch (ch)
                {
                case 1:
                    printf("Enter Name:");
                    scanf("%s", &reg.name);
                    break;
                case 2:
                    printf("Enter Number : ");
                    scanf("%d", &reg.number);
                    break;
                case 3:
                    printf("Enter Name: ");
                    scanf("%s", &reg.name);
                    printf("Enter number: ");
                    scanf("%f", &reg.number);
                    break;
                default:
                    printf("Invalid Selection");
                    break;
                }
                fwrite(&reg, sizeof(reg), 1, fpt);
            }
        }
        fclose(fpo);
        fclose(fpt);
        fpo = fopen("Record", "w");
        fpt = fopen("TempFile", "r");
        while (fread(&reg, sizeof(reg), 1, fpt))
        {
            fwrite(&reg, sizeof(reg), 1, fpo);
        }
        fclose(fpo);
        fclose(fpt);
        printf("RECORD UPDATED");
    }
}

void deletefile()
{
    FILE *fpo;
    FILE *fpt;
    int r, s;
    printf("Enter the Number you want to delete :");
    scanf("%d", &r);
    if (avlnumber(r) == 0)
        printf("Number no %d is not available in the file\n", r);
    else
    {
        fpo = fopen("Record", "r");
        fpt = fopen("TempFile", "w");
        while (fread(&reg, sizeof(reg), 1, fpo))
        {
            s = reg.number;
            if (s != r)
                fwrite(&reg, sizeof(reg), 1, fpt);
        }
        fclose(fpo);
        fclose(fpt);
        fpo = fopen("Record", "w");
        fpt = fopen("TempFile", "r");
        while (fread(&reg, sizeof(reg), 1, fpt))
            fwrite(&reg, sizeof(reg), 1, fpo);
        printf("\nRECORD DELETED\n");
        fclose(fpo);
        fclose(fpt);
    }

}

void search()
{
    FILE *fp2;
    int r, s, avl;
    printf("\nEnter the Number no you want to search  :");
    scanf("%d", &r);
    avl = avlnumber(r);
    if (avl == 0)
        printf("Number No %d is not available in the file\n",r);
    else
    {
        fp2 = fopen("Record", "r");
        while (fread(&reg, sizeof(reg), 1, fp2))
        {
            s = reg.number;
            if (s == r)
            {
                printf("\nName:\t %s",reg.name);
                printf("\nNumber:\t %d",reg.number);
                printf("\nAge:\t %d",reg.age);
                printf("\nAddress:\t %s",reg.address);
                printf("\nMedium:\t %s\n",reg.medium );
                printf("\nType:\t %s\n",reg.type );
                printf("Exam Area: %s \n",reg.area);




            }
        }
        fclose(fp2);
    }
}
int avlnumber(int rno)
{
    FILE *fp;
    int c = 0;
    fp = fopen("Record", "r");
    while (!feof(fp))
    {
        fread(&reg, sizeof(reg), 1, fp);

        if (rno == reg.number)
        {
            fclose(fp);
            return 1;
        }
    }
    fclose(fp);
    return 0;
}
void sort()
{
    int a[20], count = 0, i, j, t, c;
    FILE *fpo;
    fpo = fopen("Record", "r");
    while (fread(&reg, sizeof(reg), 1, fpo))
    {
        a[count] = reg.number;
        count++;
    }
    c = count;
    for (i = 0; i<count - 1; i++)
    {
        for (j = i + 1; j<count; j++)
        {
            if (a[i]>a[j])
            {
                t = a[i];
                a[i] = a[j];
                a[j] = t;
            }
        }
    }
    printf("Number\t\t\tName\t\t\tAge\t\tAddress\t\tMedium\t\tType\t\tArea\n\n");
    count = c;
    for (i = 0; i<count; i++)
    {
        rewind(fpo);
        while (fread(&reg, sizeof(reg), 1, fpo))
        {
            if (a[i] == reg.number)
                printf("\n%d\t\t%s\t\t\t%d\t\t%s\t\t%s\t\t%s\t\t%s",reg.number, reg.name,reg.age,reg.address,reg.medium,reg.type,reg.area);
        }

    }
}




int main()
{
    int ra;
rs:
    system("cls");
    printf("\n1.Registration\n ");
    printf("\n2.Admin Panel\n");
    printf("\n3.EXIT\n");
    scanf("%d",&ra);

    if(ra==1)
    {
        registration() ;
    }
    else if(ra==2)
    {
        adminpanel();
    }else if(ra==3){
      exit(1);
    }
    else
    {
        printf("\nYou Must Input 1 Or 2");
        getch();
        goto rs;
    }

}



void registration ()
{

//struct registration reg;
    printf("\nEnter details :\n");

    FILE *fp;
    fp = fopen("Record", "a");



    printf("\nEnter Your Number: ");
    scanf("%d",&reg.number);
    printf("\nEnter Your Full Name: ");
    scanf("\n");
    gets(reg.name);
    printf("\nEnter Your Age: ");
    scanf("%d",&reg.age);
    printf("\nEnter Your Address: ");
    scanf("\n");
    gets(reg.address);
    printf("\nEnter Your Medium: \n");
    printf("1.IELTS on computer\n");
    printf("2.IELTS on paper\n");
    scanf("%s",&reg.medium);

    printf("\nWhich IELTS test would you like to take?\n");
    printf("1.IELTS Academic\n");
    printf("2.IELTS General Training\n");
    scanf("%s",&reg.type);
    printf("Select your venue:\n");
    printf("1.Dhanmondi\n2.Kalabagan\n3.Banani\n4.Mirpur\n5.online\n");
    scanf("%s",&reg.area);


    system("cls");
    printf("\nName:\t %s",reg.name);
    printf("\nNumber:\t %d",reg.number);
    printf("\nAge:\t %d",reg.age);
    printf("\nAddress:\t %s",reg.address);
    printf("\nMedium:\t %s\n",reg.medium );
    printf("Type:\t %s\n",reg.type );
    printf("Exam will be held in %s \n",reg.area);

    fwrite(&reg, sizeof(reg), 1, fp);
    fclose(fp);
   getch();
    main();
}

Md Amir Hamzah

Md. Amir Hamzah is an overthinker by mind and a writer by heart! Along with pursuing his BSC in CSE, he is always on the verge to try something new with each sunrise in the tech and social world! Come join him in the journey and find answers to your queries! Right now I am working on The Tech Breach website www.thetechbreach.com/

Leave a Reply

Your email address will not be published. Required fields are marked *