-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathvoiture.c
146 lines (130 loc) · 2.82 KB
/
voiture.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
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
#include "voiture.h"
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <gtk/gtk.h>
enum
{
MARQUE,
MODELE,
COULEUR,
PRIX,
COLUMNS
};
void ajouter_resvoit(reserve *r)
{FILE *f;
f=fopen("voiturereser.bin","rb");
if(f!=NULL)
{
fwrite(r,sizeof(reserve),1,f);
fclose(f);
}
}
void Ajouter_voit(ajout *T)
{FILE *f;
f=fopen("voiture.bin","ab");
if(f!=NULL)
{
fwrite(T,sizeof(ajout),1,f);
fclose(f);
}
}
void Afficher (GtkWidget *liste,ajout T)
{
GtkCellRenderer *renderer;
GtkTreeViewColumn *column;
GtkTreeIter iter;
GtkListStore *store;
char Marque[20];
char Modele[20];
char Couleur[20];
int prix[20];
store=NULL;
FILE *f;
store=gtk_tree_view_get_model(GTK_TREE_VIEW(liste));
if (store==NULL)
{
renderer=gtk_cell_renderer_text_new();
column=gtk_tree_view_column_new_with_attributes(" Marque", renderer,"text",MARQUE,NULL);
gtk_tree_view_append_column(GTK_TREE_VIEW (liste), column);
renderer=gtk_cell_renderer_text_new();
column= gtk_tree_view_column_new_with_attributes(" Modele", renderer,"text",MODELE,NULL);
gtk_tree_view_append_column(GTK_TREE_VIEW (liste), column);
renderer=gtk_cell_renderer_text_new();
column= gtk_tree_view_column_new_with_attributes(" Couleur", renderer,"text",COULEUR,NULL);
gtk_tree_view_append_column(GTK_TREE_VIEW (liste), column);
renderer=gtk_cell_renderer_text_new();
column= gtk_tree_view_column_new_with_attributes(" Prix", renderer,"text",PRIX,NULL);
gtk_tree_view_append_column(GTK_TREE_VIEW (liste), column);
}
store= gtk_list_store_new (COLUMNS,G_TYPE_STRING,G_TYPE_STRING,G_TYPE_STRING,G_TYPE_STRING);
f=fopen("voiture.bin","rb");
if(f!=NULL)
{while(fread(&T,sizeof(ajout),1,f)==1)
{
gtk_list_store_append(store, &iter);
gtk_list_store_set(store,&iter,MARQUE,T.Marque,MODELE,T.Modele,COULEUR,T.Couleur,PRIX,T.Prix,-1);
}
}
fclose(f);
gtk_tree_view_set_model(GTK_TREE_VIEW (liste), GTK_TREE_MODEL(store));
g_object_unref(store);
}
/*
typedef struct AJOUTER
{
ajv jr;
int Prix;
char Marque[20];
char Modele[20];
char Couleur[20];
}ajout;
}reserve;
*/
/*void modifier(char marque,char modele,char couleur,char prix)
{
FILE *f,*f1;
char var[50];char var1[50];char var2;char var3[50];
f=fopen("voiture","ab");
f1=fopen("","a+");
while(fscanf(f,sizeof())=1)
{
if (strcmp(var3,prix)==0)
else
fprintf(f1,);
}
fclose(f1);
fclose(f);
rename("src/tampo.txt","src/admin.txt");
}*/
void dell_user(char *marque)
{
ajout T;
FILE *old;
FILE *new=NULL;
new=fopen("voiture_test.bin","wb");
fclose(new);
old=fopen("voiture.bin","rb");
new=fopen("voiture_test.bin","ab");
int i=0;
while(!(feof(old)))
{i++;
fread(&T,1,sizeof(ajout),old);}
fclose(old);
old=fopen("voiture.bin","rb");
int j=0;
while(j<i-1)
{
j++;
fread(&T,1,sizeof(ajout),old);
g_print("pseudo:%s \n",T.Marque);
if(strcmp(T.Marque,marque))
{
fwrite(&T,sizeof(ajout),1,new);
}
}
fclose(new);
fclose(old);
remove("voiture.bin");
rename("voiture_test.bin","voiture.bin");
}