githubEdit

Add Students

A function made to add students data to database

circle-info

About: This function is responsible for inputting the data of a student. It prompts the user to enter various information about the student and performs basic validation checks on some fields.

1. studentInput() function

circle-exclamation

1.1: Description:

This function is responsible for taking input from the user to populate the fields of a student structure. (reference: Structures (structs))

1.2: Syntax:

short form:

void studentInput(student *e); //routine
studentInput(myStudent); // call function

full form:

void studentInput(student *e) {
    char filename[100];

    printw("Enter Student id (layout: yyyy[bac_id]): ");
    scanw("%llu", &(e->id));

    printw("Enter Student's first name : ");
    scanw("%s", e->nom);

    printw("Enter Student's last name : ");
    scanw("%s", e->prenom);

    printw("Enter Student's home adress: ");
    scanw(" %[^\n]", e->adresse);

    CHECKPOINT1:
    printw("Enter Student's Email: ");
    scanw("%s", e->email);
    if(!check(isEmail, e->email)){
        printw("\nInvalid email !\n");
        goto CHECKPOINT1;
    }

    CHECKPOINT2:
    printw("Enter Student's age: ");
    scanw("%d", &(e->age));
    if(!check(age, e->age)){
        printw("\nInvalid age value !\n");
        goto CHECKPOINT2;
    }
}

1.3: Parameters:

  • e: Pointer to a student structure (see in Structures (structs)). The input values entered by the user will be stored in the fields of this structure.

1.4: Input:

The function prompts the user to enter various details of the student, such as their ID, first name, last name and home address. The input values are read from the terminal.

for Email and Age, function firstly creates a label called "CHECKPOINT" before input, then it prompts the user to enter it's data, after that function calls the check() function (explained in: Input Checker Function) to verify if input data are valid or not, if it's not it tells user that data are invaild and takes him back to reprompt that kind of data again:

1.5: Output:

The function does not return any value. Instead, it populates the fields of the student structure passed as a parameter.

1.6: Usage:

This function will be called and wrapped by studentInput() when we need to gather input for a student object.

2. addStudent() function

2.1: Description:

This function allows the user to add multiple student records. It prompts the user for the number of students to add, creates a directory for storing student data files if it doesn't exist, and then iteratively collects input for each student.

2.2: Syntax:

short form:

full form (definition):

2.3: Input:

The function prompts the user to enter the number of students to add and provides a prompt for entering student data using studentInput() function.

2.4: Output:

The function creates a directory named "database" (if it doesn't already exist) to store student data files.

circle-exclamation

It saves the entered student data into separate text files, with each file containing the details of one student. The file names are generated using the student's first name and last name.

2.5: Usage:

This function can be used to interactively add student records to a database-like system.

triangle-exclamation

Last updated