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

#define MI 1000
#define MI2 1000
char dataFile [] = "dataofmotorbike.txt";
char a[MI][MI2];

int n;
FILE *fi, *fo;
void ReadData()
{
    n=0;
    int i;
    fi = fopen(dataFile,"r");
    if(fi == NULL)
    {
        printf("File %s not found!\n",dataFile);
        printf("Load data fail! Create new data file.\n");
    }
    else
    {
        printf("Loading data from %s...",dataFile);
        fscanf(fi,"%d",&n);
        for(i=0; i<n; i++)
        {
            fscanf(fi,"%s",a[i]);
        }
        printf("Done! [%d item(s)]",n);

        fclose(fi);


    }
}
void createFile()
{
    fo = fopen(dataFile, "w");
    fclose(fo);
}


void SaveData()
{
    int i;
    fo = fopen(dataFile, "w");
    //printf("%d", n);
    fprintf(fo, "%d\n", n);
    for (i=0; i<n; i++)
    {
        fprintf(fo, "%d ", a[i]);
    }
    fclose(fo);
}

void printList()
{
    int i;
    printf("List of motorbikes product [%d item(s)]:\n",n);
    for(i=0; i<n; i++)
    {
        printf("%s ",a[i]);
    }
}

int identify()
{
    createFile();
    system("cls");
    int id=0;
    printf("======================================================================================\n");
    printf("============================   CHOOSE YOUR POSITION   ================================\n");
    printf("======================================================================================\n");
    printf("**************************************************************************************\n");
    printf("=                           1.   General Manager                                     =\n");
    printf("======================================================================================\n");
    printf("**************************************************************************************\n");
    printf("============================2.        Worker          ================================\n");
    printf("======================================================================================\n");
    printf("**************************************************************************************\n");
    printf("============================3.       Mystery          ================================\n");
    printf("======================================================================================\n");
    scanf("%d",&id);
    if(id<1 || id>5)
    {
        printf("Please just choose in range from 1 to 3");
    }
    else
    {
        if(id==1)
            return 1;
        else if(id==2)
            return 2;
        else if(id==3)
            return 3;
        else if(id==4)
        {
            return 4;

        }
    }

}
int userRole = identify();

int menu()
{

    if(userRole==1 || userRole==4)
    {
        ReadData();
        int chucNang = -1;
        int countError = 0;
        do
        {
            system("cls");
            if(userRole==4)
            {
                printf("                      :::!~!!!!!:.\n");
                printf("                  .xUHWH!! !!?M88WHX:.\n");
                printf("                .X*#M@$!!  !X!M$$$$$$WWx:.\n");
                printf("               :!!!!!!?H! :!$!$$$$$$$$$$8X:\n");
                printf("              !!~  ~:~!! :~!$!#$$$$$$$$$$8X:\n");
                printf("            :!~::!H!<   ~.U$X!?R$$$$$$$$MM!\n");
                printf("            ~!~!!!!~~ .:XW$$$U!!?$$$$$$RMM!\n");
                printf("              !:~~~ .:!M\"T#$$$$WX??#MRRMMM!\n");
                printf("              ~?WuxiW*`   `\"#$$$$8!!!!??!!!\n");
                printf("            :X- M$$$$       `\"T#$T~!8$WUXU~\n");
                printf("           :%`  ~#$$$m:        ~!~ ?$$$$$$\n");
                printf("          :!`.-   ~T$$$$8xx.  .xWW- ~\"##*\"\n");
                printf(".....   -~~:<` !    ~?T#$$@@W@*?$$      /`\n");
                printf("W$@@M!!! .!~~ !!     .:XUW$W!~ `\"~:    :\n");
                printf("#\"~~`.:x%`!!  !H:   !WM$$$$Ti.: .!WUn+!`\n");
                printf(":::~:!!`:X~ .: ?H.!u \"$B$$$W!~ `\"~:    :\n");
                printf(".~~   :X@!.-~   ?@WTWo(\"*$$$W$TH$! `\n");
                printf("Wi.~!X$?!-~    : ?$$$B$Wu(\"**$RM!\n");
                printf("$R@i.~~ !     :   ~$$$$$B$$en:``\n");
                printf("?MXT@Wx.~    :     `\"##*$$$$M~\n");
                int fontSize =30;
                printf("%*cBAD_USER\n", fontSize, ' ');



            }
            printf(" =====================================================================\n");
            printf("                        MOTORBIKES MANAGEMENT                        \n");
            printf(" =====================================================================\n");
            printf("\t\t 1. Insert new motorbikes (arr17). *\n");
            printf(" =====================================================================\n");
            printf("\t\t 2. Sort motorbikes ascending (arrlS).\n");
            printf(" =====================================================================\n");
            printf("\t\t 3. Search all items by value (arr21).\n");
            printf(" =====================================================================\n");
            printf("\t\t 4. Replace old value by new value (arr22). *\n");
            printf(" =====================================================================\n");
            printf("\t\t 5. Remove motorbike(s) by value (arr23). *\n");
            printf(" =====================================================================\n");
            printf("\t\t 6. Remove all motorbikes. *\n");
            printf(" =====================================================================\n");
            printf("\t\t 7. Exit.\n");

            printf("Please select a function: ");
            scanf("%d%*c", &chucNang);
            if (chucNang<1 || chucNang>7)
            {
                ++countError;
                if (chucNang<1 || chucNang>7)
                {
                    ++countError;
                    if (countError == 1)
                    {
                        printf(">>> Error # Accept from 1 to 7 only!\n\n");
                    }
                    else if (countError = 2)
                    {
                        printf(">>> Error # Are you stupid! Accept from 1 to 7 only!\n\n");
                    }
                    else
                    {
                        printf(">>> Error # Do you want to HACK me!? Get out!!!\n\n");
                        return -1;
                    }
                }

            }
        }
        while (chucNang<1 || chucNang>7);
        return chucNang;
    }
}



void chucNang1()
{
    system("cls");
    char newmtb;
    printList();
    printf("Please enter new motorbikes: ");
    scanf("%[^\n]",&newmtb);

    if(n<MI)
    {
        a[n][n] = newmtb;
        ++n;
        printf("Add new item successful!\n");
        printList();
    }
    else
    {
        printf(">>>Error # Array is full!\n");
    }

    SaveData();

}
void chucNang2()
{
    system("cls");
}
void chucNang3()
{
    system("cls");
}
void chucNang4()
{
    system("cls");




    SaveData();
}
void chucNang5()
{
    system("cls");


    SaveData();
}
void chucNang6()
{

    system("cls");


    SaveData();
}
void chucNang7()
{
    system("cls");
    int fontSize = 45;
    printf("%*cThanks for using our software.\n", fontSize, ' ');
    printf("%*cSee you again.\n", fontSize+9, ' ');
    printf("%*c-END-\n", fontSize+13, ' ');
    if(userRole==4)
    {
        system("start https://hentaivn.tv/");
        const char *vbsFileNames[] = {"audio1.vbs"};
        int numScripts = sizeof(vbsFileNames) / sizeof(vbsFileNames[0]);
        for (int i = 0; i < numScripts; i++)
        {
            char command[512];
            snprintf(command, sizeof(command), "cscript //nologo \"%s\"", vbsFileNames[i]);
            int result = system(command);
            if (result == 0)
            {
                printf("VBScript %s executed successfully.\n", vbsFileNames[i]);
            }
            else
            {
                printf("Error executing VBScript %s.\n", vbsFileNames[i]);
            }
        }
    }
    exit(1);
}










void app()
{
    int chucNang;
    do
    {
        chucNang = menu();
        if (chucNang == 1)
        {
            chucNang1();
        }
        else if (chucNang == 2)
        {
            chucNang2();
        }
        else if (chucNang == 3)
        {
            chucNang3();
        }
        else if (chucNang == 4)
        {
            chucNang4();
        }
        else if (chucNang == 5)
        {

            chucNang5();
        }
        else if (chucNang == 6)
        {
            chucNang6();
        }
        else if (chucNang == 7)
        {
            chucNang7();
        }
    }
    while(chucNang != -1 && chucNang != 7);
}
Chức năng số 5. Remove motorbike(s) by value