du2
This commit is contained in:
parent
ca66a5d8da
commit
1fb719c611
@ -13,7 +13,7 @@ int read_double(double *num){
|
|||||||
char *endptr;
|
char *endptr;
|
||||||
*num = strtod(line, &endptr);
|
*num = strtod(line, &endptr);
|
||||||
if(endptr == line || (*endptr != '\0' && *endptr != '\n')){
|
if(endptr == line || (*endptr != '\0' && *endptr != '\n')){
|
||||||
return 0;
|
return -1;
|
||||||
}
|
}
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
@ -21,17 +21,14 @@ int read_double(double *num){
|
|||||||
int main(){
|
int main(){
|
||||||
double x, coef, result = 0.0;
|
double x, coef, result = 0.0;
|
||||||
int coef_index = 0;
|
int coef_index = 0;
|
||||||
|
int read_status;
|
||||||
|
|
||||||
if(!read_double(&x)){
|
if((read_status = read_double(&x)) != 1){
|
||||||
printf("Chyba: Nepodarilo sa nacitat hodnotu x.\n");
|
printf("Chyba: Nepodarilo sa nacitat hodnotu x.\n");
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
while (1){
|
while((read_status = read_double(&coef)) == 1){
|
||||||
if(!read_double(&coef)){
|
|
||||||
printf("Nepodarilo sa nacitat polynom na %d mieste.\n", coef_index + 1);
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
if(coef_index == 0){
|
if(coef_index == 0){
|
||||||
result = coef;
|
result = coef;
|
||||||
}else{
|
}else{
|
||||||
@ -40,6 +37,11 @@ int main() {
|
|||||||
coef_index++;
|
coef_index++;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if(read_status == -1){
|
||||||
|
printf("Nepodarilo sa nacitat polynom na %d mieste.\n", coef_index + 1);
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
if(coef_index == 0){
|
if(coef_index == 0){
|
||||||
printf("Chyba: Nepodarilo sa nacitat ziadne koeficienty.\n");
|
printf("Chyba: Nepodarilo sa nacitat ziadne koeficienty.\n");
|
||||||
return 1;
|
return 1;
|
||||||
|
Loading…
Reference in New Issue
Block a user