diff --git a/a1/program.c b/a1/program.c index 004c252..3d9f98f 100644 --- a/a1/program.c +++ b/a1/program.c @@ -1,69 +1,155 @@ -#include -#include -#include -#include -#include - -int main(){ - - char pole[100]; - double cislo1; - double cislo2; - double vysledok; - char znamienko; - char* token; - char vysledky[50][50]; // pole pre ukladanie vysledkov - int pocet = 0; - - while (1) { - char* a = fgets(pole, 100, stdin); - - if (pole[0] == '\n') { //ci je riadok prazdny, ci sa stlacil enter - break; - } - - token = strtok(pole, " "); //rozdelenie retazca podla medzier - cislo1 = atof(token); // premena stringu na desatinne cislo a priradenie cislu1 - token = strtok(NULL, " "); //pokracovanie v rozdelovani retazca - znamienko = token[0]; //vrati ukazatel na nasledujuci token, cize znamienko - token = strtok(NULL, " =\n"); - cislo2 = atof(token); - token = strtok(NULL, " =\n"); - vysledok = atof(token); - - double realny; - - switch (znamienko){ - case '+': - realny = cislo1 + cislo2; - break; - case '-': - realny = cislo1 - cislo2; - break; - case '*': - realny = cislo1 * cislo2; - break; - case '/': - realny = cislo1 / cislo2; - break; - default: - printf("CHYBA\n"); - return 1; - } - - if (realny == vysledok){ - strcpy(vysledky[pocet], "OK"); //kopiruje vysledok do pola vysledky - } - else{ - strcpy(vysledky[pocet], "ZLE"); - } - pocet++; - } - - //vypis vysledkov - for (int i = 0; i < pocet; i++) { - printf("%s\n", vysledky[i]); - } - - return 0; +#include +#include +#include +#include +#include + + +struct uloha{ + + float result; + char Output[25]; +}; + + +char* ClearString(const char* str) { + const char* separator = " "; // Declare separator as const pointer + char* novy_string = malloc(strlen(str) + 1); // Allocate memory for new string + if (novy_string == NULL) { + + return NULL; + } + novy_string[0] = '\0'; // Initialize the new string + + char* token; + char* kopie_str = strdup(str); // Make a copy of the original string + if (kopie_str == NULL) { + free(novy_string); // Free memory allocated for new string + + return NULL; + } + + // Get the first token + token = strtok(kopie_str, separator); + + // Iterate through the remaining tokens + while (token != NULL) { + strcat(novy_string, token); // Append token to the new string + token = strtok(NULL, separator); // Get the next token + } + + free(kopie_str); // Free the copied string as it's no longer needed + + return novy_string; +} + + + +int main(){ + + char pole[100]; + memset(pole,0,100); + + char CistePole[100]; + + float cislo1; + float cislo2; + char znamienko; + + char* token; + int priklad = 0; + + int chyba = 0; + + struct uloha excel[100]; + + while (1) { + char* a = fgets(pole, 100, stdin); + + if (pole[0] == '\n' || a == NULL ) { + break; + } +//CHECK + for(int i = 0; i