diff --git a/du4/program.c b/du4/program.c index 1cf4302..c12b6dc 100644 --- a/du4/program.c +++ b/du4/program.c @@ -1,100 +1,128 @@ #include -#include -#include -#include -char* compactString(char *src,int leng) { - char *new_str = (char*)calloc(leng+1,sizeof(char)); - int k=0; - for(int i=0;i +#include +#include +#include + +struct res{ + double na,nb,result; + char sign; +}list [10]; + +int fill(double*,double*,char *,double *); +double count(const double*,const double *,char); +int aget(double *); +int sget(char *); +int efinde(void); +char checkend(void); + +int main(){ + int cond; + char fcond=1; + int i; + for(i=0;fcond!=EOF;i++){ + fcond=checkend(); + if(fcond==EOF) + break; + + cond=aget(&list[i].na); + if(cond<0){ + printf("CHYBA\n"); + return 0;} + cond=sget(&list[i].sign); + if(cond<0){ + printf("CHYBA\n"); + return 0;} + cond=aget(&list[i].nb); + if(cond<0){ + printf("CHYBA\n"); + return 0;} + cond=efinde(); + if(cond<0){ + printf("CHYBA\n"); + return 0;} + cond=aget(&list[i].result); + if(cond<0){ + printf("CHYBA\n"); + return 0;} + /*if((fcond=checkend())!='\n'){ + printf("1CHYBA %d\n",(int)fcond); + return 0;}*/ + if(fcond==-1) + break; + //printf("%lf %c %lf = %lf\n",list[i].na,list[i].sign,list[i].nb,list[i].result); } - return new_str; -} - - - -double operation(double first,double second,char c){ - double x =0; - if(c=='*'){ - x=first*second; - return x; - } - else if(c =='-'){ - x=first-second; - return x; - } - else if(c=='/'){ - x=first/second; - return x; - } - x= first+second; - return x; -} - - -double round_to(double value, double eps) -{ - - return floor(value/eps + 0.5) * eps; -} - -double compare_percent(double a, double b, double eps) -{ - double diff = round_to( (a - b) * 2 / (a + b), eps); - return diff < 0 ? -1 : diff > 0 ? +1 : 0; -} - -int check(char *str){ - int flag=0; - char symb[5]="*-+/="; - for(int i =0;i='a'&&str[i]<='z')||(str[i]>='A'&&str[i]<='Z')||str[i]==','){ + for(int x=0;x