logo of SA Coder
        Menu
sign in

      References

file name - "data.c"

copy


short data(FILE *fa, long long pass)
{
    FILE *tf;
    fflush(fa);
repeat:
    fseek(fa, 0, SEEK_END);
    if (ftell(fa) == sizeof(long long) + sizeof(int))
    {
        printf(" ---> Not found any Lable <---\n");
        return -1;
    }

    fseek(fa, sizeof(long long) + sizeof(int), SEEK_SET);
    int size;
    printf(" ---> Add the detail sequentially <---\n  ");
    while (1)
    {
        if (fread(&size, sizeof(size), 1, fa) == 0)
        {
            break;
        }
        char read_name[size];
        if (fread(read_name, sizeof(read_name), 1, fa) == 0)
        {
            break;
        }
        if ((tf = fopen(read_name, "rb")) == 0)
        {
            printf("\n ---> Some file are missing <---\n");
            return -1;
        }
        else
        {
            fclose(tf);
        }
        printf(" %s", read_name);
        size = size - strlen(read_name) - 1;
        while (size > 0)
        {
            printf(" ");
            size--;
        }
    }
    printf("\n   ");
    fseek(fa, sizeof(long long) + sizeof(int), SEEK_SET);
    while (1)
    {
        if (fread(&size, sizeof(size), 1, fa) == 0)
        {
            break;
        }
        char read_name[size];
        if (fread(read_name, sizeof(read_name), 1, fa) == 0)
        {
            break;
        }
        if ((tf = fopen(read_name, "ab")) == 0)
        {
            printf(" ---> Some files Error <---\n");
            return -1;
        }
        char temp_data[size];
        scanf("%s", temp_data);
        fwrite(temp_data, sizeof(temp_data), 1, tf);
        fclose(tf);
    }
    fflush(fa);
    printf(" ---> Your data will be successfully added <---\n ---> Would you like to add more data (y/n)(default y) <---\n");
    fflush(stdin);
    char y = getchar();
    if (y == 'y' || y == 10)
    {
        goto repeat;
    }
    return 0;
}



In this article, we will be discussing how to implement data input functionality in a DBMS using the C programming language. Specifically, we will be focusing on the data.c file, which is a key component of our DBMS program. The data.c file contains the code that allows users to input data into the database. Let's take a closer look at the code and how it works. The first function in the data.c file is called "short data". This function takes two parameters - a pointer to a file (fa) and a long long integer (pass). The "fa" pointer is used to point to the file containing the database, while the "pass" integer is used to store a password for accessing the database (which we won't be covering in this article). The "short data" function starts by opening the file pointed to by "fa" and flushing any buffered data to ensure that we are starting with a clean slate. Next, the function uses a loop to iterate through each record in the database. If no records are found, the function returns an error message. If records are found, the function prints the details of each record to the console, asking the user to input data for each field. Once the user has entered data for each field, the function writes the data to the appropriate file in the database and repeats the process until the user chooses to stop adding data. Overall, the "short data" function provides a simple yet effective way for users to input data into the DBMS using C programming language. By understanding how this function works, you will be well on your way to building your own DBMS application using C.



Click on the next button for source code of next file



Please login first to comment.