-
Notifications
You must be signed in to change notification settings - Fork 0
/
DataBase.c
73 lines (56 loc) · 1.42 KB
/
DataBase.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
71
72
/*
*
* Author: Amanzou Amine, Jeremy Paulino
*
* Created on 20 mai 2012
*/
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include "DataBase.h"
DB_type LittleBD[MAX_SIZE];
unsigned int c_table = 0;
char *nameLittleDB = NULL;
void create_bd(char *namedb) {
nameLittleDB = (char *)malloc(sizeof(strlen(namedb)));
nameLittleDB = namedb;
}
int add_table(char *nametable, table *t) {
if (c_table < MAX_SIZE - 1) {
LittleBD[c_table].nameTable = nametable;
LittleBD[c_table].t = t;
LittleBD[c_table].nb_line = 0;
return c_table++;
}
else return -1;
}
int search_table(char *nametable) {
int i = 0;
while ((i < c_table) && !strcmp(LittleBD[i].t->name,nametable)) {
i++;
}
if (i == c_table) return -1;
else /* (strcmp(LittleBD[i].t->name,nametable)) */
return i;
}
table *addr_table(char *nametable) {
int r = search_table(nametable);
if (r == -1) return NULL;
else return LittleBD[r].t;
}
int increase_line(char *nametable) {
int r = search_table(nametable);
if (r == -1) return -1;
else {
LittleBD[r].nb_line++;
return LittleBD[r].nb_line;
}
}
int decrease_line(char *nametable) {
int r = search_table(nametable);
if (r == -1) return -1;
else {
LittleBD[r].nb_line--;
return LittleBD[r].nb_line;
}
}