From a0efe44b760469d32e5e2c0fac6ac3439c7eb0fb Mon Sep 17 00:00:00 2001 From: Peter Sabol Date: Thu, 31 Mar 2022 10:05:03 +0200 Subject: [PATCH] funguje --- du4/program | Bin 5978 -> 7351 bytes du4/program.c | 138 +++++++++++++++++++++++++++++++++++++------------- 2 files changed, 104 insertions(+), 34 deletions(-) diff --git a/du4/program b/du4/program index cf3e0d47e93934087ed3ff53be1c66d3cee67611..713cc1158b8a9c7c8a5d877d1f5965059479e77b 100755 GIT binary patch literal 7351 zcmbVReQ+Da6<^7+5y42#2M~x$)S?8F+KLlQND53X+xd3B9VjK`kS*C#ktHLYAZDOV zDmjVA@sMdlOJ_m|Wu`-0{-D!LNNI*T7!siA)TESY3N3URI&v``LqaeVP=CMOTXJ^9 zG-YSr?f%|-`}Xbb+r7QL?=Eg$;&3>GPEJuGi0XS>?mFc03MHu%KH(NsVy37RWnfWO zw*@*NSpk(w!E=F1CKsp(iuj+EB==;*u8)aSk$vQp|ZBGMnY$(6~y}^f%{OHen>z`=}COWq_`X8>U zq|6Jt5L6C=i{ldQ(LVKPkG4G^H|PS;B+x}5CXOZbX@hl$w^T`2B=3op{}|}l7_w#; zLM!R|gg(&yELdp@@&`0PPMn*7ueM`UfW91vczM`Ik0K{S`LsL-{cqru@MP zH~~De6Z49EGJ>TSdG#Y2Ux9#*wRUpO76@Z`%PJ!rNkuwhX)}^)S=AU%CL%4N)_6o1 zMn`8dVWiDa$}|jNthn1)Z|OD0L+NxRt*RHTj3(N26Kh~297`CPbR;a=+vAyZRCHy` zw2*Ak-Vs5$EfkL@+rUc2BMG$KW_EW)j8=opkeO@;i#9EHIzzF9SlYb2q0yKhxc0MB ztsDs_W}Wk{pNtkKB0$BCQ-mSYlRh;TLwJ;k7c5?d#7=QsS`uP(ughJAz~T6nGSHA; z07EY32tqe=40Jhj=v6RBP)=ixfSk@8!Cc84f#qY4z}}D@apzCL-qyi;Fe820j|+uD z&wyE)UkzsVIrnXYmIp!R15O>i#@K|?q^u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Mv1-!pN&$%Ga`p*g84V1YKm>2^>7FQt39`EvvIIJheM?B)-@yu=p&yPBl z$f5iLqU!J>M~(NNg~?Q@Ce7Axheggl=lmIinZNh~Ag zc_XnL9iA%^^F)&8hs1Js@|=)Z&ZheI71$%qeJ}Owh1}l~V^EN|k0s^_CHJeu{PGLI zeJL?_xUk+;B<4z%cLIsIV@m?J0OC?w{rz#sO9#Qc)WeIT(s*}2{&mOGd0T4H%q zP~YeRF`L!ae@?0AO+nrvB%W(wt~-f&bCK&yV%}VCr2;YET05%7BmSP}2q^z9+*D{` zuYC`2V<&6C#~nBbtnN|NKMHL9GehpeO{o*P>YocI(;;Bqy^vuY`owd{c`gvU@TD7M z!A^|Fxz31RgRZ7u@n?t&z|MHz0apI_<@^X(jh_qScO6*yqyA1f;C@Cm{Ld8&fcc-8 zD|H6qD|ZCoN8LK$9`v6pb%xs~3}7|hevDSa!RKs01#JC$MY$O9?*ryJ4G8_?kl0{7VQPIu1}r-7YsGQW55>3R$n-6 zX3T77rxwOL&f3~Gy}4;)JD!bhJuc~Hw;ty6QbwpJBS)34M^buMBGq9e^oW^CXLKXm zD{v9(Nkq+PL|d`y%N4LZ2}$RbP+stKT-wroLS6|Y+3xN>G;tuEH_36-o^+}U7f37W z`nKTuI=!wX#MdsX52`$_8Q!o$Uuy}jZ>j~$p|Kvygx=7+VNI}E-%ww_v94Wj53Xsh zqdDtoE1bz%(f*Hjx8ACiT36K6d&0UI%O-bf9le6LQ~5MzKbO_isMj%!OVql&+O~Bk z7w>E1m=hlL^hhS9$Bblz4}MJ(Ug{=1$Bnl$)*%i7B1mFf>>=pv(PO*OXWXUjD(f|G e(ig;W&w;l*tU`0VMylE1Go@NI;~yz4@BanK$LG-i diff --git a/du4/program.c b/du4/program.c index 766d97b..6cd1b0c 100644 --- a/du4/program.c +++ b/du4/program.c @@ -2,75 +2,145 @@ #include #include #include +#include -int main() { +int main(){ - int i,j; // pro cyklus - double number1, number2, summary, rsum, msum; /*aby se mohlo počítat s desetinnými čísly*/ - char operand, equ; //načítání znaků - - scanf("%lf", &number1); // nacte prvni cislo, znamenko, druhe cislo - scanf("%c", &operand); - scanf("%lf", &number2); - scanf("%c", &equ); - scanf("%lf",&msum); + int i,j; + double number1, number2, summary, rsum, msum; + char operand, equ; +/* char input[1000]; + char num_str[30] = {0}; + float numbers[3]; + fgets(input, 999, stdin); + for (int i = 0, j =0; i < strlen(input); i++) { + char c = input[i]; + if (c==' ') continue; + if (c=='+') operand='+'; + if (c=='-') operand='-'; + if (c=='*') operand='*'; + if (c=='/') operand='/'; + if (c=='\n') break; + if (isdigit(c)) {num_str[j++] = c - '0';} + else if (j > 0) { + j = 0; + numbers[...] = atof(num_str); + } + } + } + // scanf("%lf", &number1); + //scanf("%lf", &number2); + //scanf("%lf",&msum); + +*/ + char* input = calloc(1000, 1); + while (1) { + + input = fgets(input, 1000, stdin); + if (input == NULL) break; + + fflush(stdin); + if (input[0] == '\n' || input[0] == EOF || strlen(input) <= 0) + break; + + float values[3] = {0}; + char operation = 0; + + int k = 0; + int num = strlen(input); + for (int i = 0; i < num; i++) { + + if (input[i] == ' ') + continue; + + if (isalpha(input[i])) + break; + - /*pokud se operand rovna deleni a delitel se rovna nule vypise chybu*/ - if((operand == '/') && (number2 == 0)){ + if (i < strlen(input) && (isdigit(input[i]) || input[i] == '.' || (input[i] == '-' && isdigit(input[i + 1])))) { + char temp[100] = {0}; + for (int j = 0; i < strlen(input) && (isdigit(input[i]) || input[i] == '.' || input[i] == '-'); j++) { + temp[j] = input[i++]; + } + i--; + + values[k++] = (float)atof(temp); + } else if (isdigit(input[i]) == 0 && input[i] != ' ' && input[i] != '\n' && input[i] != '=') { + + operation = input[i]; + } + } + + + if (k != 3) { + printf("CHYBA\n"); + continue; + } + + + if (operation == 0 && values[1] < 0) { + operation = '-'; + values[1] = abs(values[1]); + } + + + float result = 0; + + + +//////////////////////////////////////////////// + + /*if((operand == '/') && (number2 == 0)){ printf("Nulou sa nedá deli"); } if(operand !='+' && operand !='-' && operand !='*' && operand !='/'){ return 1; printf("\n"); - } - if(equ !='='){ - return 1; - printf("\n"); - - } - - else if(operand=='+'){ - rsum=number1+number2; + } + */ + msum=values[2]; + if(operation=='+'){ + rsum=values[0]+values[1]; if(msum==rsum){ printf("OK\n"); } else{ printf("ZLE\n"); } - printf("%lf\n",rsum); + //printf("%lf\n",rsum); } - else if(operand=='-'){ - rsum=number1-number2; + else if(operation=='-'){ + rsum=values[0]-values[1]; if(msum==rsum){ printf("OK\n"); } else{ printf("ZLE\n"); } - printf("%lf\n",rsum); + //printf("%lf\n",rsum); } - else if(operand=='*'){ - rsum=number1*number2; + else if(operation=='*'){ + rsum=values[0]*values[1]; if(msum==rsum){ printf("OK\n"); } else{ printf("ZLE\n"); } - printf("%lf\n",rsum); + //printf("%lf\n",rsum); } - else if(operand=='/'){ - rsum=number1/number2; + else if(operation=='/'){ + rsum=values[0]/values[1]; if(msum==rsum){ printf("OK\n"); } else{ printf("ZLE\n"); } - printf("%lf\n",rsum); - } -} - + //printf("%lf\n",rsum); + } + } + } \ No newline at end of file