Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdlib.h>
- #include <stdio.h>
- #include <progbase.h>
- #include <progbase/console.h>
- #include <string.h>
- #include <ctype.h>
- #include <stdbool.h>
- #include <assert.h>
- #include <math.h>
- #define LENGTH 10
- #define BUFF_LENGTH 500
- struct Staff
- {
- char staffName[50];
- int staffAmmount;
- };
- struct Organisation
- {
- char organisationName[50];
- int income;
- float rating;
- char country[50];
- struct Staff staff;
- };
- struct Organisation *fillTheStruct(char *nameO, int income, float rating, char *country, char *name, int ammount);
- void freeStruct(struct Organisation *organisations[]);
- struct Organisation *rewriteTheOrganisation(char *nameO, int income, float rating, char *country, char *name, int ammount, int index, struct Organisation *organisations[]);
- struct Organisation *rewriteTheField(char *str, char *strNew, struct Organisation *organisation);
- void newArray(struct Organisation *organisation, int length);
- void cleanBuffer();
- int getTheIndex(int pos, int count);
- void getTheInd(int *pos, int *n, struct Organisation *organisations[]);
- float getFloatValue(int pos);
- int getTheValue(int pos);
- int countStructs(int length, struct Organisation *array[]);
- bool addNewStruct(int length, struct Organisation *newOrganisation, struct Organisation *array[]);
- struct Organisation *removeOrganisation(int length, int index, struct Organisation *array[]);
- bool compTheStruct(struct Organisation *organisation1, struct Organisation *organisation2);
- void printTheOrganisation(struct Organisation *organisation, int count, int *pos);
- void getTheStruct(char *nameO, int *income, float *rating, char *country, char *staffName, int *ammount, int *pos);
- void fromSomeCountry(int length, struct Organisation *organisations[], char *country, struct Organisation *fromSomeCountry[]);
- struct Organisation *copyTheOrganisation(struct Organisation *organisations[], int indexFrom, int indexTo);
- void printTheCommand();
- void printTheMenu();
- void cleanTheInput2();
- void cleanTheInput3();
- void cleanTheInput4();
- void cleanTheOutput();
- void cleanTheCommand();
- void task1(struct Organisation *organisations[]);
- void task2();
- int staffToStr(struct Staff * staff, char * buffer, int BUFF__LENGTH);
- int strToStaff(const char *buffer, struct Staff * staff);
- bool staffEquals(struct Staff *a, struct Staff *b);
- int organisationToStr(struct Organisation * organisation, char * buffer, int BUFF__LENGTH);
- int strToOrganisation(const char *buffer, struct Organisation * organisation);
- bool organisationEquals(struct Organisation *a, struct Organisation *b);
- void printTheOrganisation2(struct Organisation * organisation);
- bool organisationsEquals(struct Organisation *a[], struct Organisation *b[]);
- int organisationsToStr(struct Organisation * organisations[], char * buffer, int BUFF__LENGTH);
- int strToOrganisations(const char *buffer, struct Organisation * organisations[]);
- int main(void)
- {
- struct Staff staff = {"Anna", 54};
- char str[50] = "";
- staffToStr(&staff,str,BUFF_LENGTH);
- puts(str);
- struct Staff test;
- char strstr[50] = "Anna#54";
- int nread = strToStaff(str,&test);
- assert(staffEquals(&test,&((struct Staff) {"Anna",54})) == 1);
- printf("%i\n",nread);
- struct Organisation organisation = {"name", 50,1.20, "country", {"Ivan",54}};
- char strtest[50] = "";
- organisationToStr(&organisation,strtest,BUFF_LENGTH);
- struct Organisation org;
- strToOrganisation(strtest,&org);
- puts(strtest);
- printTheOrganisation2(&org);
- assert(organisationEquals(&org,&((struct Organisation) {"name", 50,1.20, "country", {"Ivan",54}})) == 1);
- struct Organisation s1 = {"name", 50,1.20, "country", {"Ivan",54}};
- struct Organisation s2 = {"name1", 51,1.30, "countrie", {"Petro",55}};
- struct Organisation * organisations[LENGTH] = {
- &s1,&s2
- };
- char buff[BUFF_LENGTH] = "";
- organisationsToStr(organisations,buff,BUFF_LENGTH);
- puts(buff);
- struct Organisation * orgtest[LENGTH]= {0};
- strToOrganisations(buff,orgtest);
- //assert(organisationsEquals(organisations,orgtest) == 1);
- // struct Organisation organisation = {"Svitoch", 500000,9.5,"Ukraine",{"Ivan","Accountant"}};
- // char str[50] = "staffName";
- // char strNew[50] = "Petro";
- // struct Organisation * org = rewriteTheField(str,strNew,&organisation);
- // printTheOrganisation(org);
- // struct Organisation org2 = {"Svitoch", 500000,9.5,"Ukraine",{"Petro","Accountant"}};
- //ASSERTS
- //assert(compTheStruct(org,&org2) == 1);
- // printTheMenu();
- // char n;
- // while (n != 27)
- // {
- // struct ConsoleSize consoleSize = Console_size();
- // int maxRows = consoleSize.rows;
- // int maxColumns = consoleSize.columns;
- // Console_setCursorPosition(maxRows - 1, 13);
- // n = Console_getChar();
- // switch (n)
- // {
- // case 49:
- // {
- // struct Organisation *organisations[LENGTH] = {0};
- // task1(organisations);
- // freeStruct(organisations);
- // printTheMenu();
- // break;
- // }
- // case 50:
- // {
- // task2();
- // break;
- // }
- // default:
- // {
- // Console_setCursorPosition(maxRows - 2, 13);
- // puts("ERROR : Invalid input. Please, try again:");
- // Console_setCursorPosition(maxRows - 1, 13);
- // }
- // }
- // }
- // Console_clear();
- // Console_setCursorPosition(0, 0);
- return EXIT_SUCCESS;
- }
- bool organisationsEquals(struct Organisation *a[], struct Organisation *b[]){
- if (countStructs(LENGTH,a) != countStructs(LENGTH,b)) return false;
- for (int i = 0;i < countStructs(LENGTH,a);i++)
- {
- if (strcmp(a[i]->organisationName, b[i]->organisationName) == 1
- && a[i]->income != b[i]->income && fabs(a[i]->rating - b[i]->rating) >= 1e-4 && strcmp(a[i]->country,b[i]->country) != 0 && !staffEquals(&a[i]->staff,&b[i]->staff))
- return false;
- }
- return true;
- }
- int organisationsToStr(struct Organisation * organisations[], char * buffer, int BUFF__LENGTH)
- {
- int nwrite = snprintf(buffer, BUFF__LENGTH, "%i|\n", countStructs(LENGTH,organisations));
- int totalWrite = nwrite;
- for (int i = 0; i < countStructs(LENGTH,organisations);i++)
- {
- struct Organisation * st = organisations[i];
- totalWrite += organisationToStr(st ,buffer + totalWrite, BUFF__LENGTH - totalWrite);
- totalWrite += snprintf(buffer + totalWrite,BUFF__LENGTH - totalWrite, "\n");
- }
- return totalWrite;
- }
- int strToOrganisations(const char *buffer, struct Organisation * organisations[]){
- int nread = 0;
- int count = 0;
- sscanf(buffer, "%i|\n%n", &count, &nread);
- int totalRead = nread;
- printf("%i\n",nread);
- printf("%i\n",count);
- printf("%s\n",buffer + totalRead);
- // for (int i = 0;i < count;i++)
- // {
- struct Organisation * org = {0};
- char p[50];
- totalRead += strToOrganisation(buffer + totalRead,org);
- //sscanf(buffer + totalRead, "\n%n", &nread);
- // totalRead += nread;
- // }
- return totalRead;
- }
- bool organisationEquals(struct Organisation *a, struct Organisation *b){
- return strcmp(a->organisationName, b->organisationName) == 0
- && a->income == b->income && fabs(a->rating - b->rating) < 1e-4 && strcmp(a->country,b->country) == 0 && staffEquals(&a->staff,&b->staff);
- }
- int strToStaff(const char *buffer, struct Staff * staff){
- int nread = 0;
- puts(buffer + 2);
- sscanf(buffer, "%49[^#]%*c%i%n",
- staff->staffName,
- &(staff->staffAmmount),
- &nread);
- return nread;
- }
- int strToOrganisation(const char *buffer, struct Organisation * organisation){
- int nread = 0;
- puts(buffer);
- sscanf(buffer, "%49[^:]%*c%i:%f:%49[^:]%*c%n",
- organisation->organisationName,
- &(organisation->income),
- &(organisation->rating),
- organisation->country,
- &nread);
- printf("%s\n",organisation->organisationName);
- printf("%i\n",nread);
- puts(buffer + 10);
- int staffRead = strToStaff(buffer + nread,&organisation->staff);
- return nread ;
- }
- int organisationToStr(struct Organisation * organisation, char * buffer, int BUFF__LENGTH)
- {
- int nwrite = snprintf(buffer, BUFF__LENGTH, "%s:%i:%f:%s:", organisation->organisationName,organisation->income,organisation->rating,organisation->country);
- int staffWrite = staffToStr(&organisation->staff,buffer + nwrite, BUFF__LENGTH - nwrite);
- return nwrite + staffWrite;
- }
- int staffToStr(struct Staff * staff, char * buffer, int BUFF__LENGTH)
- {
- int nwrite = snprintf(buffer,BUFF_LENGTH, "%s#%i",
- staff->staffName,
- staff->staffAmmount);
- return nwrite;
- }
- bool staffEquals(struct Staff *a, struct Staff *b){
- return strcmp(a->staffName, b->staffName) == 0
- && a->staffAmmount == b->staffAmmount;
- }
- void printTheOrganisation2(struct Organisation * organisation)
- {
- printf("Organisation Name: %s", organisation->organisationName);
- printf("Income: %i", organisation->income);
- printf("Rating: %.2f", organisation->rating);
- printf("Country: %s", organisation->country);
- printf("Headmaster Name: %s", organisation->staff.staffName);
- printf("Ammount of staff: %i", organisation->staff.staffAmmount);
- }
- // void printTheMenu()
- // {
- // Console_clear();
- // struct ConsoleSize consoleSize = Console_size();
- // int maxRows = consoleSize.rows;
- // int maxColumns = consoleSize.columns;
- // Console_setCursorPosition(maxRows / 2 - 5, maxColumns / 2 - 50);
- // printf("HELLO! WELCOME INTO MY PROGRAMM!PLEASE, CHOOSE BEST CASE FOR YOU:");
- // Console_setCursorPosition(maxRows / 2 - 4, maxColumns / 2 - 30);
- // printf("1.CREATE NEW EMPTY LIST OF ORGANISATIONS\n");
- // Console_setCursorPosition(maxRows / 2 - 3, maxColumns / 2 - 30);
- // printf("2.READ EXISTING LIST FROM FILE\n");
- // Console_setCursorPosition(maxRows / 2 - 2, maxColumns / 2 - 30);
- // printf("----To EXIT press \"ESC\"---- \n");
- // Console_setCursorPosition(maxRows - 1, 0);
- // printf("Your input:");
- // }
- // void task1(struct Organisation *organisations[])
- // {
- // struct ConsoleSize consoleSize = Console_size();
- // int maxRows = consoleSize.rows;
- // Console_clear();
- // Console_setCursorPosition(0, 0);
- // printTheCommand();
- // Console_setCursorPosition(12, 0);
- // printf("Your input:");
- // Console_setCursorPosition(12, 13);
- // char command;
- // while (command != 27)
- // {
- // Console_setCursorPosition(12, 13);
- // command = Console_getChar();
- // cleanTheInput3();
- // switch (command)
- // {
- // case 49:
- // {
- // cleanTheCommand();
- // Console_setCursorPosition(0, 0);
- // printTheCommand();
- // Console_setCursorAttribute(FG_INTENSITY_CYAN);
- // Console_setCursorPosition(2, 0);
- // printf("~1.ADD NEW ORGANISATION WITH YOUR DATA");
- // Console_setCursorAttribute(FG_DEFAULT);
- // cleanTheInput3();
- // int pos = 12;
- // if (countStructs(LENGTH, organisations) < LENGTH)
- // {
- // char name[50] = "";
- // int income;
- // float rating;
- // char country[50] = "";
- // char staffName[50] = "";
- // int ammount;
- // getTheStruct(name, &income, &rating, country, staffName, &ammount, &pos);
- // if (addNewStruct(LENGTH, fillTheStruct(name, income, rating, country, staffName, ammount), organisations))
- // {
- // cleanTheOutput();
- // int k = 1;
- // printTheOrganisation(organisations[countStructs(LENGTH, organisations) - 1], countStructs(LENGTH, organisations) - 1, &k);
- // }
- // }
- // else
- // {
- // Console_setCursorPosition(11, 13);
- // puts("ERROR : Too many organisations. Please, try another command:");
- // cleanTheInput4();
- // Console_setCursorPosition(10, 13);
- // }
- // break;
- // }
- // case 50:
- // {
- // cleanTheCommand();
- // Console_setCursorPosition(0, 0);
- // printTheCommand();
- // Console_setCursorAttribute(FG_INTENSITY_CYAN);
- // Console_setCursorPosition(3, 0);
- // printf("~2.DELETE ORGANISATION ON SOME POSITION");
- // Console_setCursorAttribute(FG_DEFAULT);
- // int pos = 12;
- // int n;
- // if (countStructs(LENGTH, organisations) == 0)
- // {
- // Console_setCursorPosition(11, 13);
- // puts("ERROR : There is no organisations to delete. Please, try another command:");
- // cleanTheInput4();
- // Console_setCursorPosition(10, 13);
- // }
- // else
- // {
- // getTheInd(&pos, &n, organisations);
- // struct Organisation *removedOrganisation = removeOrganisation(LENGTH, n, organisations);
- // cleanTheOutput();
- // Console_setCursorPosition(1, 80);
- // puts("Removed organisation:");
- // int k = 2;
- // printTheOrganisation(removedOrganisation, n, &k);
- // }
- // break;
- // }
- // case 51:
- // {
- // cleanTheCommand();
- // Console_setCursorPosition(0, 0);
- // printTheCommand();
- // Console_setCursorAttribute(FG_INTENSITY_CYAN);
- // Console_setCursorPosition(4, 0);
- // printf("~3.REWRITE SOME ORGANISATION");
- // Console_setCursorAttribute(FG_DEFAULT);
- // cleanTheInput3();
- // int pos = 12;
- // int n;
- // getTheInd(&pos, &n, organisations);
- // char name[50] = "";
- // int income;
- // float rating;
- // char country[50] = "";
- // char staffName[50] = "";
- // int ammount;
- // getTheStruct(name, &income, &rating, country, staffName, &ammount, &pos);
- // struct Organisation *rewritten = rewriteTheOrganisation(name, income, rating, country, staffName, ammount, n, organisations);
- // cleanTheOutput();
- // Console_setCursorPosition(1, 80);
- // puts("Rewritten organisation:");
- // int k = 2;
- // printTheOrganisation(rewritten, n, &k);
- // break;
- // }
- // case 52:
- // {
- // cleanTheCommand();
- // Console_setCursorPosition(0, 0);
- // printTheCommand();
- // Console_setCursorAttribute(FG_INTENSITY_CYAN);
- // Console_setCursorPosition(5, 0);
- // printf("~4.REWRITE THE FIELD OF SOME ORGANISATION");
- // Console_setCursorAttribute(FG_DEFAULT);
- // cleanTheInput3();
- // int pos = 12;
- // int n;
- // getTheInd(&pos, &n, organisations);
- // Console_setCursorPosition(pos++, 13);
- // puts("Enter the name of the field you want to rewrite:");
- // Console_setCursorPosition(pos++, 13);
- // char nameField[50];
- // fgets(nameField, 50, stdin);
- // nameField[strlen(nameField) - 1] = '\0';
- // while (strcmp(nameField, "Organisation Name") && strcmp(nameField, "Income") && strcmp(nameField, "Rating") && strcmp(nameField, "Country") && strcmp(nameField, "Headmaster Name") && strcmp(nameField, "Ammount of staff"))
- // {
- // for (int i = 12; i < consoleSize.columns; i++)
- // {
- // Console_setCursorPosition(11, i);
- // puts(" ");
- // }
- // for (int i = 12; i < consoleSize.columns; i++)
- // {
- // Console_setCursorPosition(pos - 1, i);
- // puts(" ");
- // }
- // Console_setCursorPosition(11, 13);
- // puts("ERROR : Invalid input. Please, try again:");
- // for (int i = 12; i < consoleSize.columns; i++)
- // {
- // Console_setCursorPosition(pos - 1, i);
- // puts(" ");
- // }
- // Console_setCursorPosition(pos - 1, 13);
- // strcpy(nameField, "");
- // fgets(nameField, 50, stdin);
- // nameField[strlen(nameField) - 1] = '\0';
- // }
- // for (int i = 12; i < consoleSize.columns; i++)
- // {
- // Console_setCursorPosition(11, i);
- // puts(" ");
- // }
- // Console_setCursorPosition(pos++, 13);
- // puts("Enter the new value:");
- // Console_setCursorPosition(pos++, 13);
- // char newValue[50];
- // fgets(newValue, 50, stdin);
- // newValue[strlen(newValue) - 1] = '\0';
- // if (!strcmp(nameField, "Income") || !strcmp(nameField, "Ammount of staff"))
- // {
- // int nread = atoi(newValue);
- // while (nread == 0 || atoi(newValue) < 0)
- // {
- // if (newValue[0] == '0')
- // {
- // break;
- // }
- // else
- // {
- // for (int i = 12; i < consoleSize.columns; i++)
- // {
- // Console_setCursorPosition(11, i);
- // puts(" ");
- // }
- // for (int i = 12; i < consoleSize.columns; i++)
- // {
- // Console_setCursorPosition(pos - 1, i);
- // puts(" ");
- // }
- // Console_setCursorPosition(11, 13);
- // puts("ERROR : Invalid input. Please, try again:");
- // for (int i = 12; i < consoleSize.columns; i++)
- // {
- // Console_setCursorPosition(pos - 1, i);
- // puts(" ");
- // }
- // Console_setCursorPosition(pos - 1, 13);
- // strcpy(newValue, "");
- // fgets(newValue, 50, stdin);
- // newValue[strlen(newValue) - 1] = '\0';
- // nread = atoi(newValue);
- // }
- // }
- // }
- // for (int i = 12; i < consoleSize.columns; i++)
- // {
- // Console_setCursorPosition(9, i);
- // puts(" ");
- // }
- // if (!strcmp(nameField, "Rating"))
- // {
- // float nread = atof(newValue);
- // while (nread == 0)
- // {
- // if (newValue[0] == '0' || atof(newValue) < 0)
- // {
- // break;
- // }
- // else
- // {
- // for (int i = 12; i < consoleSize.columns; i++)
- // {
- // Console_setCursorPosition(11, i);
- // puts(" ");
- // }
- // for (int i = 12; i < consoleSize.columns; i++)
- // {
- // Console_setCursorPosition(pos - 1, i);
- // puts(" ");
- // }
- // Console_setCursorPosition(11, 13);
- // puts("ERROR : Invalid input. Please, try again:");
- // for (int i = 12; i < consoleSize.columns; i++)
- // {
- // Console_setCursorPosition(pos - 1, i);
- // puts(" ");
- // }
- // Console_setCursorPosition(pos - 1, 13);
- // strcpy(newValue, "");
- // fgets(newValue, 50, stdin);
- // newValue[strlen(newValue) - 1] = '\0';
- // nread = atof(newValue);
- // }
- // }
- // }
- // for (int i = 12; i < consoleSize.columns; i++)
- // {
- // Console_setCursorPosition(11, i);
- // puts(" ");
- // }
- // struct Organisation *rewritten1 = rewriteTheField(nameField, newValue, organisations[n]);
- // cleanTheOutput();
- // Console_setCursorPosition(1, 80);
- // puts("Rewritten organisation:");
- // int k = 2;
- // printTheOrganisation(rewritten1, n, &k);
- // break;
- // }
- // case 53:
- // {
- // cleanTheCommand();
- // Console_setCursorPosition(0, 0);
- // printTheCommand();
- // Console_setCursorAttribute(FG_INTENSITY_CYAN);
- // Console_setCursorPosition(6, 0);
- // printf("~5.FIND ALL ORGANISATIONS FROM SOME COUNTRY");
- // Console_setCursorAttribute(FG_DEFAULT);
- // cleanTheInput3();
- // struct Organisation *FCountry[LENGTH] = {0};
- // char country[50];
- // int pos = 12;
- // Console_setCursorPosition(pos++, 13);
- // puts("Enter the name of the country:");
- // Console_setCursorPosition(pos++, 13);
- // fgets(country, 50, stdin);
- // country[strlen(country) - 1] = '\0';
- // cleanTheOutput();
- // int ps = 1;
- // fromSomeCountry(LENGTH, organisations, country, FCountry);
- // for (int i = 0; i < countStructs(LENGTH, FCountry); i++)
- // {
- // printTheOrganisation(FCountry[i], 1, &ps);
- // }
- // break;
- // }
- // case 54:
- // {
- // cleanTheCommand();
- // Console_setCursorPosition(0, 0);
- // printTheCommand();
- // Console_setCursorAttribute(FG_INTENSITY_CYAN);
- // Console_setCursorPosition(7, 0);
- // printf("~6.COPY THE DATA FROM ONE ORGANISATION TO ANOTHER");
- // Console_setCursorAttribute(FG_DEFAULT);
- // cleanTheInput3();
- // int pos = 12;
- // Console_setCursorPosition(pos++, 13);
- // puts("The organisation you want to copy data from:");
- // int nFrom;
- // getTheInd(&pos, &nFrom, organisations);
- // Console_setCursorPosition(pos++, 13);
- // puts("The organisation you want to copy data to:");
- // int nTo;
- // getTheInd(&pos, &nTo, organisations);
- // struct Organisation *copied = copyTheOrganisation(organisations, nFrom, nTo);
- // cleanTheOutput();
- // Console_setCursorPosition(1, 80);
- // puts("Rewritten organisation:");
- // int ps = 2;
- // printTheOrganisation(copied, nTo, &ps);
- // break;
- // }
- // case 55:
- // {
- // cleanTheCommand();
- // Console_setCursorPosition(0, 0);
- // printTheCommand();
- // Console_setCursorAttribute(FG_INTENSITY_CYAN);
- // Console_setCursorPosition(7, 0);
- // printf("~7.SAVE DATA TO SOME COMPUTER FILE");
- // Console_setCursorAttribute(FG_DEFAULT);
- // cleanTheInput3();
- // break;
- // }
- // case 27:
- // {
- // break;
- // }
- // default:
- // {
- // Console_setCursorPosition(11, 13);
- // puts("ERROR : Invalid input. Please, try again:");
- // cleanTheInput4();
- // Console_setCursorPosition(12, 13);
- // break;
- // }
- // }
- // conHideCursor();
- // for (int i = 12; i < consoleSize.rows; i++)
- // {
- // for (int x = 12; x < consoleSize.columns; x++)
- // {
- // Console_setCursorPosition(i, x);
- // puts(" ");
- // }
- // }
- // conShowCursor();
- // Console_setCursorPosition(12, 13);
- // }
- // }
- // void task2()
- // {
- // }
- // struct Organisation *copyTheOrganisation(struct Organisation *organisations[], int indexFrom, int indexTo)
- // {
- // strcpy(organisations[indexTo]->organisationName, organisations[indexFrom]->organisationName);
- // organisations[indexTo]->income = organisations[indexFrom]->income;
- // organisations[indexTo]->rating = organisations[indexFrom]->rating;
- // strcpy(organisations[indexTo]->country, organisations[indexFrom]->country);
- // strcpy(organisations[indexTo]->staff.staffName, organisations[indexFrom]->staff.staffName);
- // organisations[indexTo]->staff.staffAmmount = organisations[indexFrom]->staff.staffAmmount;
- // return organisations[indexTo];
- // }
- // struct Organisation *rewriteTheOrganisation(char *nameO, int income, float rating, char *country, char *name, int ammount, int index, struct Organisation *organisations[])
- // {
- // strcpy(organisations[index]->organisationName, nameO);
- // organisations[index]->income = income;
- // organisations[index]->rating = rating;
- // strcpy(organisations[index]->country, country);
- // strcpy(organisations[index]->staff.staffName, name);
- // organisations[index]->staff.staffAmmount = ammount;
- // return organisations[index];
- // }
- // void getTheInd(int *pos, int *n, struct Organisation *organisations[])
- // {
- // Console_setCursorPosition(*pos, 13);
- // *pos = *pos + 1;
- // puts("Enter index:");
- // Console_setCursorPosition(*pos, 13);
- // *pos = *pos + 1;
- // *n = getTheIndex(*pos - 1, countStructs(LENGTH, organisations) - 1);
- // }
- // void getTheStruct(char *nameO, int *income, float *rating, char *country, char *staffName, int *ammount, int *pos)
- // {
- // Console_setCursorPosition(*pos, 13);
- // *pos = *pos + 1;
- // puts("Enter name:");
- // Console_setCursorPosition(*pos, 13);
- // *pos = *pos + 1;
- // fgets(nameO, 50, stdin);
- // nameO[strlen(nameO) - 1] = '\0';
- // Console_setCursorPosition(*pos, 13);
- // *pos = *pos + 1;
- // puts("Enter income:");
- // Console_setCursorPosition(*pos, 13);
- // *pos = *pos + 1;
- // *income = getTheValue(*pos - 1);
- // Console_setCursorPosition(*pos, 13);
- // *pos = *pos + 1;
- // puts("Enter rating:");
- // Console_setCursorPosition(*pos, 13);
- // *pos = *pos + 1;
- // *rating = getFloatValue(*pos - 1);
- // Console_setCursorPosition(*pos, 13);
- // *pos = *pos + 1;
- // puts("Enter country:");
- // Console_setCursorPosition(*pos, 13);
- // *pos = *pos + 1;
- // fgets(country, 50, stdin);
- // country[strlen(country) - 1] = '\0';
- // Console_setCursorPosition(*pos, 13);
- // *pos = *pos + 1;
- // puts("Enter headmaster name:");
- // Console_setCursorPosition(*pos, 13);
- // *pos = *pos + 1;
- // fgets(staffName, 50, stdin);
- // staffName[strlen(staffName) - 1] = '\0';
- // Console_setCursorPosition(*pos, 13);
- // *pos = *pos + 1;
- // puts("Enter ammount of staff:");
- // Console_setCursorPosition(*pos, 13);
- // *pos = *pos + 1;
- // *ammount = getTheValue(*pos - 1);
- // }
- // void fromSomeCountry(int length, struct Organisation *organisations[], char *country, struct Organisation *fromSomeCountry[])
- // {
- // int j = 0;
- // for (int i = 0; i < countStructs(length, organisations); i++)
- // {
- // if (!strcmp(organisations[i]->country, country))
- // {
- // fromSomeCountry[j++] = organisations[i];
- // }
- // }
- // }
- // void printTheCommand()
- // {
- // printf("AVAILABLE COMMANDS:\n1.ADD NEW ORGANISATION WITH YOUR DATA\n2.DELETE ORGANISATION ON SOME POSITION\n"
- // "3.REWRITE SOME ORGANISATION\n4.REWRITE THE FIELD OF SOME ORGANISATION\n5.FIND ALL ORGANISATIONS FROM SOME COUNTRY\n"
- // "6.COPY THE DATA FROM ONE ORGANISATION TO ANOTHER\n7.SAVE DATA TO SOME COMPUTER FILE\n---If you want to return to the MENU press \"ESC\"---");
- // }
- // void printTheOrganisation(struct Organisation *organisation, int count, int *pos)
- // {
- // int output = 80;
- // Console_setCursorPosition(*pos, output);
- // *pos = *pos + 1;
- // printf("============%i organisation============", count);
- // Console_setCursorPosition(*pos, output);
- // *pos = *pos + 1;
- // printf("Organisation Name: %s", organisation->organisationName);
- // Console_setCursorPosition(*pos, output);
- // *pos = *pos + 1;
- // printf("Income: %i", organisation->income);
- // Console_setCursorPosition(*pos, output);
- // *pos = *pos + 1;
- // printf("Rating: %.2f", organisation->rating);
- // Console_setCursorPosition(*pos, output);
- // *pos = *pos + 1;
- // printf("Country: %s", organisation->country);
- // Console_setCursorPosition(*pos, output);
- // *pos = *pos + 1;
- // printf("Headmaster Name: %s", organisation->staff.staffName);
- // Console_setCursorPosition(*pos, output);
- // *pos = *pos + 1;
- // printf("Ammount of staff: %i", organisation->staff.staffAmmount);
- // }
- // bool compTheStruct(struct Organisation *organisation1, struct Organisation *organisation2)
- // {
- // if (!strcmp(organisation1->organisationName, organisation2->organisationName) && organisation1->income == organisation2->income
- // && organisation1->rating == organisation2->rating
- // && !strcmp(organisation1->country, organisation2->country)
- // && !strcmp(organisation1->staff.staffName, organisation2->staff.staffName) && organisation1->staff.staffAmmount == organisation2->staff.staffAmmount)
- // return 1;
- // return 0;
- // }
- // struct Organisation *fillTheStruct(char *nameO, int income, float rating, char *country, char *name, int ammount)
- // {
- // struct Organisation *organisation = malloc(sizeof(struct Organisation));
- // strcpy(organisation->organisationName, nameO);
- // organisation->income = income;
- // organisation->rating = rating;
- // strcpy(organisation->country, country);
- // strcpy(organisation->staff.staffName, name);
- // organisation->staff.staffAmmount = ammount;
- // return organisation;
- // }
- // void freeStruct(struct Organisation *organisations[])
- // {
- // for (int i = 0; i < countStructs(LENGTH, organisations); i++)
- // {
- // free(organisations[i]);
- // }
- // }
- // struct Organisation *rewriteTheField(char *str, char *strNew, struct Organisation *organisation)
- // {
- // if (!strcmp(str, "Organisation Name"))
- // {
- // strcpy(organisation->organisationName, strNew);
- // }
- // else if (!strcmp(str, "Income"))
- // {
- // organisation->income = atoi(strNew);
- // }
- // else if (!strcmp(str, "Rating"))
- // {
- // organisation->rating = atof(strNew);
- // }
- // else if (!strcmp(str, "Country"))
- // {
- // strcpy(organisation->country, strNew);
- // }
- // else if (!strcmp(str, "Headmaster Name"))
- // {
- // strcpy(organisation->staff.staffName, strNew);
- // }
- // else if (!strcmp(str, "Ammount of staff"))
- // {
- // organisation->staff.staffAmmount = atoi(strNew);
- // }
- // return organisation;
- // }
- // int getTheValue(int pos)
- // {
- // struct ConsoleSize consoleSize = Console_size();
- // int maxRows = consoleSize.rows;
- // int n;
- // Console_setCursorPosition(pos, 13);
- // int nread = scanf("%i", &n);
- // cleanBuffer();
- // while (nread != 1)
- // {
- // for (int i = 12; i < consoleSize.columns; i++)
- // {
- // Console_setCursorPosition(11, i);
- // puts(" ");
- // }
- // for (int i = 12; i < consoleSize.columns; i++)
- // {
- // Console_setCursorPosition(pos, i);
- // puts(" ");
- // }
- // Console_setCursorPosition(11, 13);
- // puts("ERROR : Invalid input. Please, try again:");
- // for (int i = 12; i < consoleSize.columns; i++)
- // {
- // Console_setCursorPosition(pos, i);
- // puts(" ");
- // }
- // Console_setCursorPosition(pos, 13);
- // nread = scanf("%i", &n);
- // cleanBuffer();
- // }
- // for (int i = 12; i < consoleSize.columns; i++)
- // {
- // Console_setCursorPosition(11, i);
- // puts(" ");
- // }
- // return n;
- // }
- // int getTheIndex(int pos, int count)
- // {
- // struct ConsoleSize consoleSize = Console_size();
- // int maxRows = consoleSize.rows;
- // int n;
- // Console_setCursorPosition(pos, 13);
- // int nread = scanf("%i", &n);
- // cleanBuffer();
- // while (n < 0 || n > count)
- // {
- // for (int i = 12; i < consoleSize.columns; i++)
- // {
- // Console_setCursorPosition(11, i);
- // puts(" ");
- // }
- // for (int i = 12; i < consoleSize.columns; i++)
- // {
- // Console_setCursorPosition(pos, i);
- // puts(" ");
- // }
- // Console_setCursorPosition(11, 13);
- // puts("ERROR : There is no organisation with such an index. Please, try again:");
- // for (int i = 12; i < consoleSize.columns; i++)
- // {
- // Console_setCursorPosition(pos, i);
- // puts(" ");
- // }
- // Console_setCursorPosition(pos, 13);
- // nread = scanf("%i", &n);
- // cleanBuffer();
- // }
- // for (int i = 12; i < consoleSize.columns; i++)
- // {
- // Console_setCursorPosition(11, i);
- // puts(" ");
- // }
- // return n;
- // }
- // void cleanTheCommand()
- // {
- // conHideCursor();
- // for (int y = 0; y < 60; y++)
- // {
- // for (int x = 0; x < 8; x++)
- // {
- // conHideCursor();
- // Console_setCursorPosition(x, y);
- // puts(" ");
- // }
- // }
- // conShowCursor();
- // }
- // void cleanTheOutput()
- // {
- // conHideCursor();
- // struct ConsoleSize consoleSize = Console_size();
- // for (int y = 49; y < consoleSize.columns; y++)
- // {
- // for (int x = 0; x < consoleSize.rows; x++)
- // {
- // conHideCursor();
- // Console_setCursorPosition(x, y);
- // puts(" ");
- // }
- // }
- // conShowCursor();
- // }
- // void cleanTheInput2()
- // {
- // conHideCursor();
- // struct ConsoleSize consoleSize = Console_size();
- // int maxRows = consoleSize.rows;
- // int maxColumn = consoleSize.columns;
- // int y = maxRows - 1;
- // for (int x = 12; x < consoleSize.columns; x++)
- // {
- // Console_setCursorPosition(y, x);
- // puts(" ");
- // }
- // conShowCursor();
- // }
- // void cleanTheInput3()
- // {
- // conHideCursor();
- // struct ConsoleSize consoleSize = Console_size();
- // int maxColumn = consoleSize.columns;
- // for (int y = 11; y < consoleSize.rows; y++)
- // {
- // for (int x = 0; x < consoleSize.columns; x++)
- // {
- // Console_setCursorPosition(y, x);
- // puts(" ");
- // }
- // }
- // Console_setCursorPosition(12, 0);
- // puts("Your input:");
- // Console_setCursorPosition(12, 13);
- // conShowCursor();
- // }
- // void cleanTheInput4()
- // {
- // conHideCursor();
- // struct ConsoleSize consoleSize = Console_size();
- // int maxColumn = consoleSize.columns;
- // for (int x = 12; x < consoleSize.columns; x++)
- // {
- // Console_setCursorPosition(12, x);
- // puts(" ");
- // }
- // Console_setCursorPosition(12, 13);
- // conShowCursor();
- // }
- // void cleanBuffer()
- // {
- // char c = 0;
- // while (c != '\n')
- // {
- // c = getchar();
- // }
- // }
- // float getFloatValue(int pos)
- // {
- // struct ConsoleSize consoleSize = Console_size();
- // int maxRows = consoleSize.rows;
- // float n;
- // Console_setCursorPosition(pos, 13);
- // int nread = scanf("%f", &n);
- // cleanBuffer();
- // while (nread != 1)
- // {
- // conHideCursor();
- // for (int i = 12; i < consoleSize.columns; i++)
- // {
- // Console_setCursorPosition(11, i);
- // puts(" ");
- // }
- // for (int i = 12; i < consoleSize.columns; i++)
- // {
- // Console_setCursorPosition(pos, i);
- // puts(" ");
- // }
- // Console_setCursorPosition(11, 13);
- // puts("ERROR : Invalid input. Please, try again:");
- // for (int i = 12; i < consoleSize.columns; i++)
- // {
- // Console_setCursorPosition(pos, i);
- // puts(" ");
- // }
- // conShowCursor();
- // Console_setCursorPosition(pos, 13);
- // nread = scanf("%f", &n);
- // cleanBuffer();
- // }
- // conHideCursor();
- // for (int i = 12; i < consoleSize.columns; i++)
- // {
- // Console_setCursorPosition(11, i);
- // puts(" ");
- // }
- // conShowCursor();
- // return n;
- // }
- int countStructs(int length, struct Organisation *array[])
- {
- int count = 0;
- for (int i = 0; i < length; i++)
- {
- if (array[i] == NULL)
- {
- break;
- }
- count++;
- }
- return count;
- }
- // bool addNewStruct(int length, struct Organisation *newOrganisation, struct Organisation *array[])
- // {
- // int count = countStructs(length, array);
- // if (count == LENGTH)
- // {
- // return false;
- // }
- // else
- // {
- // array[count] = newOrganisation;
- // return true;
- // }
- // }
- // struct Organisation *removeOrganisation(int length, int index, struct Organisation *array[])
- // {
- // int count = countStructs(length, array);
- // if (index < 0 || index >= count)
- // {
- // return NULL;
- // }
- // else
- // {
- // struct Organisation *organisationToRemove = array[index];
- // for (int i = index + 1; i < count; i++)
- // {
- // array[i - 1] = array[i];
- // }
- // array[count - 1] = NULL;
- // return organisationToRemove;
- // }
- // }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement