-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathStruct.c
94 lines (76 loc) · 1.92 KB
/
Struct.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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
typedef struct Column
{
char typeToken[256];
char nameToken[256];
char valeurToken[256];
struct Column *suivC;
}Column;
typedef struct Line
{
Column *Columns;
struct Line *suivL;
}Line;
Column* allocateColumn(){
Column *col = (Column*)malloc(sizeof(Column));
col->suivC=NULL;
return col;
}
Line* allocateLine(){
Line *li = (Line*)malloc(sizeof(Line));
li->Columns=NULL;
li->suivL=NULL;
return li;
}
Line* insertLine(Line **Lign){
Line *li ;
Line *newLine;
if(*Lign==NULL){
newLine = allocateLine();
return newLine;
}else{
li = *Lign;
while (li->suivL!=NULL)
{
li = li->suivL;
}
newLine = allocateLine();
li->suivL=newLine;
return newLine;
}
}
void insertColumn(Line *Lign,char* typeToken,char* nameToken,char* valeurToken){
Column *col,*c = Lign->Columns;
if(c==NULL){
col= allocateColumn();
strcpy(col->typeToken,typeToken);
strcpy(col->nameToken,nameToken);
strcpy(col->valeurToken,valeurToken);
Lign->Columns=col;
}else{
while (c->suivC!=NULL)
{
c=c->suivC;
}
col= allocateColumn();
strcpy( col->typeToken,typeToken);
strcpy(col->nameToken,nameToken);
strcpy( col->valeurToken,valeurToken);
c->suivC=col;
}
}
Column* get_id(Line *Lign , char id[]){
Column *col = Lign->Columns;
int stop = 0;
while (stop==0 && col!=NULL){
if( strcmp(col->nameToken,id)==0){
stop = 1;
}
else{
col=col->suivC;
}
}
return col;
}