-
Notifications
You must be signed in to change notification settings - Fork 0
/
File.c
70 lines (52 loc) · 1.1 KB
/
File.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
64
65
66
67
68
69
70
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#include "File.h"
FILE* openb(char name[])
{
FILE* file = fopen(name, "rb+");
if (file == NULL) {
file = fopen(name, "wb+");
}
return file;
}
FILE* opent()
{
time_t acttime;
time(&acttime); // <--- Obtiene la hora actual.
struct tm* t = localtime(&acttime);
char filePath[32]; // Format: "Database/Backups/DD-MM-AAAA.txt"
sprintf(filePath, "Database/Actions registry/%i-%i-%i.txt", t->tm_mday, t->tm_mon + 1, t->tm_year + 1900);
FILE* file = fopen(filePath, "a");
if (file == NULL) {
file = fopen(filePath, "w");
}
return file;
}
void readi(int* valor, FILE* file)
{
fread(valor, sizeof(int), 1, file);
return;
}
void writei(int* valor, FILE* file)
{
fwrite(valor, sizeof(int), 1, file);
return;
}
void read(USUARIO* valor, FILE* file)
{
fread(valor, sizeof(USUARIO), 1, file);
return;
}
void write(USUARIO* valor, FILE* file)
{
fwrite(valor, sizeof(USUARIO), 1, file);
fflush(file);
return;
}
void close(FILE* file)
{
fclose(file);
free(file);
return;
}