-
Notifications
You must be signed in to change notification settings - Fork 0
/
filelib.c
38 lines (31 loc) · 693 Bytes
/
filelib.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
//
// Created by Lorenzo Cardinali on 20/09/2021.
//
#include <stdlib.h>
#include "filelib.h"
FILE *open_input_file(char *name) {
FILE *file = fopen(name, "rb");
if (file == NULL) {
perror("Errore apertura file input\n");
exit(1);
}
return file;
}
FILE *open_output_file(char *name) {
FILE *file = fopen(name, "wb");
if (file == NULL) {
perror("Errore apertura file output\n");
exit(1);
}
return file;
}
void close_file(FILE *file) {
if (file != NULL)
fclose(file);
}
size_t file_size(FILE *file) {
fseek(file, 0, SEEK_END);
size_t file_length = ftell(file);
rewind(file);
return file_length;
}