-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.c
63 lines (51 loc) · 1.28 KB
/
main.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
#include <stdio.h>
#include <stdlib.h>
#include "read.h"
#include "math_oper.h"
#include "arr_oper.h"
#include "print.h"
#define EXTRA_PLACES 3
#define OK 0
int main(void)
{
setbuf(stdout, NULL);
double *arr = NULL;
double *arr_end = NULL;
short int n = 0, p = 0;
double num1 = 0, num2 = 0;
short int code_err = read_array(&arr, &n, &arr_end);
if (code_err)
{
free(arr);
puts("Invalid input.");
return code_err;
}
num1_calc(&num1, arr, arr_end);
arr_end = del_from_arr(arr, arr_end, num1, &n);
arr = memory_changer(&arr, n, &code_err, &arr_end);
if (code_err)
{
free(arr);
fprintf(stderr, "Memory allocation error, try again.\n");
return code_err;
}
num2_calc(&num2, arr, arr_end);
code_err = read_number(&p, n);
if (code_err)
{
free(arr);
fprintf(stderr, "Invalid P number.\n");
return code_err;
}
arr = memory_changer(&arr, EXTRA_PLACES + n, &code_err, &arr_end);
if (code_err)
{
free(arr);
fprintf(stderr, "Memory allocation error, try again.\n");
return code_err;
}
add_to_arr(arr, arr_end - EXTRA_PLACES, arr + p, num2);
print_result(arr, arr_end);
free(arr);
return OK;
}