Bonjour,

Voilà, je travaille sur un mini-projet qui gère une petite base de donnée en C.
Et voilà je crée un topic ici pour que les personnes présentes sur ce forum puissent m'apporter de l'aide, des conseils, ou mêmes des critiques constructives.
Je mettrais a jour a chaque modification sur ce post là.
J'utilise Code::Blocks.

Merci.

[09/01/2013]: Je bloque actuellement sur la fonction affichage qui m'affiche bien tout sauf le vector DATA.
Avez vous des conseils sur comment je devrais m'y prendre pour remedier a ce problèmes

printf("%s ",a.tables->tab[i].champs->tab[j].DATA->tab[l]);} à la ligne 210.


Le code source:

Code : Sélectionner tout - Visualiser dans une fenêtre à part
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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define TYPE char;
 
void *myalloc(size_t n){
void *ret = malloc(n);
if(ret == NULL){
printf("Erreur de Malloc");
exit(1);
}
return ret;
}
 
void *my_realloc(void *p, size_t size) {
  p = realloc(p, size);
  if (p == NULL) {
    fprintf (stderr, "Erreur : impossible de reallouer la mémoire\n");
    exit(-1);
  }
  return p;
}
 
 
 
/*-----------------------------------------------------------------------------------------------------
-------------------------------------------------------------------------------------------------------
-----------------------------------------------------------------------------------------------------*/
 
 
typedef struct _vector{
char *tab;
int n;
int cap;
} *vector;
 
typedef struct _champ{
char entete[100]; 
int type_data;
vector DATA;
}champ;
 
typedef struct _cvector{
champ *tab;
int n;
int cap;
} *cvector;
 
 
typedef struct table{
char nom[100]; //nom de la table
cvector champs;
}table;
 
typedef struct _tvector{
table *tab;
int n;
int cap;
} *tvector;
 
 
typedef struct _database{
char nom[100];
table dtable;
tvector tables;
}database;
 
 
 
tvector new_tvector(){
tvector p= myalloc(sizeof(*p));
p->tab= myalloc(25 * sizeof(table));
p->cap=25;
p->n = 0;
return p;
}
 
cvector new_cvector(){
cvector r= myalloc(sizeof(*r));
r->tab= myalloc(25 * sizeof(champ));
r->cap=25;
r->n = 0;
return r;
}
 
vector new_vector(){
vector v=myalloc(sizeof(*v));
v->tab= myalloc(150*sizeof(char));
v->n=0;
v->cap=150;
return v;
}
 
champ new_champs(char *cname, int typ){
champ nouv;
strcpy(nouv.entete,cname);
nouv.type_data= typ;
nouv.DATA= new_vector();
return nouv;
}
 
table new_table(char *tname){
table nouv ;
strcpy(nouv.nom,tname);
nouv.champs = new_cvector();
return nouv;
}
 
database new_database(char *dname){
database nouv;
strcpy(nouv.nom,dname);
 
nouv.tables = new_tvector();
return nouv;
}
 
 
 
 
 
 
/* LES FONCTIONS RESERVE */
 
void reserve(vector v, int cap) {
  if (v->cap == 0) {
    v->tab = myalloc (cap *sizeof (*v->tab));
    v->cap = cap;
    return;
  }
  v->tab = my_realloc(v->tab, cap *sizeof (*v->tab));
  v->cap = cap;
  if (v->n > cap)
    v->n=cap;
}
 
 
void treserve(tvector v, int cap) {
  if (v->cap == 0) {
    v->tab = myalloc (cap *sizeof (*v->tab));
    v->cap = cap;
    return;
  }
  v->tab = my_realloc(v->tab, cap *sizeof (*v->tab));
  v->cap = cap;
  if (v->n > cap)
    v->n=cap;
}
 
void creserve(cvector v, int cap){
    if (v->cap == 0) {
    v->tab = myalloc (cap *sizeof (*v->tab));
    v->cap = cap;
    return;
  }
  v->tab = my_realloc(v->tab, cap *sizeof (*v->tab));
  v->cap = cap;
  if (v->n > cap)
    v->n=cap;
}
/*LES FONCTIONS PUSHBACK*/
 
void push_back(vector v, char DATA){
  if (v->cap == v->n) {
    if (v->cap == 0)
      reserve (v,1);
    else
      reserve (v, 2 * v->cap);
  }
  v->tab[v->n] = DATA;
  v->n++;
}
 
void tpush_back(tvector a, table b){
  if(a->cap == a->n) {
    if (a->cap == 0)
       treserve (a, 1);
    else
       treserve (a, (2 * a->cap));
  }
  a->tab[a->n] = b;
  a->n++;
  }
 
void cpush_back(cvector a, champ t){
if(a->cap == a->n) {
    if (a->cap == 0)
       creserve (a, 1);
    else
       creserve (a, (2 * a->cap));
  }
  a->tab[a->n] = t;
  a->n++;
  }
 
int sizetable(database a){
 
        return a.tables->tab->champs->n;
    }
 
 
void affiche(database a){
     int i,j,l;
     printf("%s \n", a.nom);
     for(i=0;i<2;i++){
    printf("%s \n",a.tables->tab[i].nom);
    for(j=0;j<3;j++){
    printf("%s ",a.tables->tab[i].champs->tab[j].entete);
 
     for(l=0;l<4;l++){
     printf("%s ",a.tables->tab[i].champs->tab[j].DATA->tab[l]);}
 
}}}
 
 
int main(){
    database a = new_database("Data Etudiant");
    table un=new_table("Etudiants");
    a.tables->tab[0]=un;
    champ id=new_champs("ID",0);
    un.champs->tab[0] = id;
    id.DATA->tab[0]= "1";
    id.DATA->tab[1]= "2";
    id.DATA->tab[2]= "3";
    id.DATA->tab[3]= "4";
    champ nom=new_champs("Nom",1);
    un.champs->tab[1] = nom;
    nom.DATA->tab[0]= "VLAD";
    nom.DATA->tab[1]= "RAVEEN";
    nom.DATA->tab[2]= "CIOBI";
    nom.DATA->tab[3]= "SARKO";
    champ prenom= new_champs("Prenom",1);
    un.champs->tab[2] = prenom;
    prenom.DATA->tab[0]= "JEAN";
    prenom.DATA->tab[1]= "PERERA";
    prenom.DATA->tab[2]= "STEFAN";
    prenom.DATA->tab[3]= "ZY";
 
    table deux = new_table("Notes");
    a.tables->tab[1] = deux;
    affiche(a);
}
Les Erreurs de compilation:
Compiling: C:\Users\Raveen\Downloads\main.c
C:\Users\Raveen\Downloads\main.c: In function 'main':
C:\Users\Raveen\Downloads\main.c:256: warning: assignment makes integer from pointer without a cast
C:\Users\Raveen\Downloads\main.c:257: warning: assignment makes integer from pointer without a cast
C:\Users\Raveen\Downloads\main.c:258: warning: assignment makes integer from pointer without a cast
C:\Users\Raveen\Downloads\main.c:259: warning: assignment makes integer from pointer without a cast
C:\Users\Raveen\Downloads\main.c:262: warning: assignment makes integer from pointer without a cast
C:\Users\Raveen\Downloads\main.c:263: warning: assignment makes integer from pointer without a cast
C:\Users\Raveen\Downloads\main.c:264: warning: assignment makes integer from pointer without a cast
C:\Users\Raveen\Downloads\main.c:265: warning: assignment makes integer from pointer without a cast
C:\Users\Raveen\Downloads\main.c:268: warning: assignment makes integer from pointer without a cast
C:\Users\Raveen\Downloads\main.c:269: warning: assignment makes integer from pointer without a cast
C:\Users\Raveen\Downloads\main.c:270: warning: assignment makes integer from pointer without a cast
C:\Users\Raveen\Downloads\main.c:271: warning: assignment makes integer from pointer without a cast
Linking console executable: C:\Users\Raveen\Downloads\main.exe
Process terminated with status 0 (0 minutes, 0 seconds)
0 errors, 12 warnings