48 lines
870 B
C
48 lines
870 B
C
#include <stdio.h>
|
|
#include <malloc.h>
|
|
|
|
void print_array(int *array, int length) {
|
|
if (length == 0) {
|
|
printf("\n");
|
|
return;
|
|
}
|
|
|
|
printf("|");
|
|
|
|
for (int i = 0; i < length; ++i) {
|
|
printf("%d|", array[i]);
|
|
}
|
|
printf("\n");
|
|
}
|
|
|
|
void apply_shift(int shift, int *array, int size) {
|
|
for (int i = 0; i < size; ++i) {
|
|
array[i] += shift;
|
|
}
|
|
}
|
|
|
|
int sum_array(int *array, int size) {
|
|
int sum = 0;
|
|
for (int i = 0; i < size; ++i) {
|
|
sum += array[i];
|
|
}
|
|
|
|
return sum;
|
|
}
|
|
|
|
char *read_file(char *filepath, int *len) {
|
|
FILE *f = fopen(filepath, "r");
|
|
|
|
fseek(f, 0, SEEK_END);
|
|
*len = ftell(f);
|
|
fseek(f, 0, SEEK_SET);
|
|
|
|
char *content = (char *) malloc(sizeof(char) * (*len));
|
|
fread(content, 1, *len, f);
|
|
*len = *len - 1;
|
|
content[*len] = '\0';
|
|
|
|
fclose(f);
|
|
|
|
return content;
|
|
} |