Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
P
projet_se3_2021
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Maxence Laurent
projet_se3_2021
Commits
acd4778e
Commit
acd4778e
authored
4 years ago
by
Maxence Laurent
Browse files
Options
Downloads
Patches
Plain Diff
[FIX] fuite de mémoire
parent
bb887dc9
Branches
Branches containing commit
No related tags found
No related merge requests found
Changes
4
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
Compte Rendu PA.pdf
+0
-0
0 additions, 0 deletions
Compte Rendu PA.pdf
initializeData.c
+37
-4
37 additions, 4 deletions
initializeData.c
initializeData.h
+4
-0
4 additions, 0 deletions
initializeData.h
main.c
+123
-106
123 additions, 106 deletions
main.c
with
164 additions
and
110 deletions
Compte Rendu PA.pdf
+
0
−
0
View file @
acd4778e
No preview for this file type
This diff is collapsed.
Click to expand it.
initializeData.c
+
37
−
4
View file @
acd4778e
...
@@ -95,7 +95,7 @@ void create_flight (Flight **fl, char **line, const char separators[])
...
@@ -95,7 +95,7 @@ void create_flight (Flight **fl, char **line, const char separators[])
}
}
else
else
{
{
(
*
fl
)
->
airline
=
word
;
(
*
fl
)
->
airline
=
strdup
(
word
)
;
}
}
word
=
strsep
(
line
,
separators
);
word
=
strsep
(
line
,
separators
);
if
(
strcmp
(
word
,
""
)
==
0
)
if
(
strcmp
(
word
,
""
)
==
0
)
...
@@ -104,7 +104,7 @@ void create_flight (Flight **fl, char **line, const char separators[])
...
@@ -104,7 +104,7 @@ void create_flight (Flight **fl, char **line, const char separators[])
}
}
else
else
{
{
(
*
fl
)
->
org_air
=
word
;
(
*
fl
)
->
org_air
=
strdup
(
word
)
;
}
}
word
=
strsep
(
line
,
separators
);
word
=
strsep
(
line
,
separators
);
if
(
strcmp
(
word
,
""
)
==
0
)
if
(
strcmp
(
word
,
""
)
==
0
)
...
@@ -113,7 +113,7 @@ void create_flight (Flight **fl, char **line, const char separators[])
...
@@ -113,7 +113,7 @@ void create_flight (Flight **fl, char **line, const char separators[])
}
}
else
else
{
{
(
*
fl
)
->
dest_air
=
word
;
(
*
fl
)
->
dest_air
=
strdup
(
word
)
;
}
}
word
=
strsep
(
line
,
separators
);
word
=
strsep
(
line
,
separators
);
if
(
strcmp
(
word
,
""
)
==
0
)
if
(
strcmp
(
word
,
""
)
==
0
)
...
@@ -274,8 +274,9 @@ void load_flights (Table_hash_airlines *thal, Table_hash_airports *thap, FILE *f
...
@@ -274,8 +274,9 @@ void load_flights (Table_hash_airlines *thal, Table_hash_airports *thap, FILE *f
while
(
getline
(
&
line
,
&
len
,
fd
)
!=
-
1
)
// on récupère chaque ligne.
while
(
getline
(
&
line
,
&
len
,
fd
)
!=
-
1
)
// on récupère chaque ligne.
{
{
char
*
line2
=
line
;
Flight
*
new_flight
=
malloc
(
sizeof
(
Flight
));
Flight
*
new_flight
=
malloc
(
sizeof
(
Flight
));
create_flight
(
&
new_flight
,
&
line
,
separators
);
create_flight
(
&
new_flight
,
&
line
2
,
separators
);
Liste_Airlines
*
l
=
thal
->
tab_airlines
[
hash_function_airline
(
new_flight
->
airline
)];
Liste_Airlines
*
l
=
thal
->
tab_airlines
[
hash_function_airline
(
new_flight
->
airline
)];
...
@@ -372,6 +373,9 @@ void free_all_airlines (Table_hash_airlines *thal)
...
@@ -372,6 +373,9 @@ void free_all_airlines (Table_hash_airlines *thal)
{
{
Flight
*
tmp
=
thal
->
tab_airlines
[
i
]
->
liste_flights
;
Flight
*
tmp
=
thal
->
tab_airlines
[
i
]
->
liste_flights
;
thal
->
tab_airlines
[
i
]
->
liste_flights
=
NULL
;
thal
->
tab_airlines
[
i
]
->
liste_flights
=
NULL
;
free
(
tmp
->
airline
);
free
(
tmp
->
org_air
);
free
(
tmp
->
dest_air
);
free
(
tmp
);
free
(
tmp
);
}
}
else
else
...
@@ -379,6 +383,9 @@ void free_all_airlines (Table_hash_airlines *thal)
...
@@ -379,6 +383,9 @@ void free_all_airlines (Table_hash_airlines *thal)
Flight
*
tmp
=
thal
->
tab_airlines
[
i
]
->
liste_flights
;
Flight
*
tmp
=
thal
->
tab_airlines
[
i
]
->
liste_flights
;
thal
->
tab_airlines
[
i
]
->
liste_flights
=
thal
->
tab_airlines
[
i
]
->
liste_flights
->
suiv_airline
;
thal
->
tab_airlines
[
i
]
->
liste_flights
=
thal
->
tab_airlines
[
i
]
->
liste_flights
->
suiv_airline
;
tmp
->
suiv_airline
=
NULL
;
tmp
->
suiv_airline
=
NULL
;
free
(
tmp
->
airline
);
free
(
tmp
->
org_air
);
free
(
tmp
->
dest_air
);
free
(
tmp
);
free
(
tmp
);
}
}
}
}
...
@@ -409,3 +416,29 @@ void free_all_airports (Table_hash_airports *thap)
...
@@ -409,3 +416,29 @@ void free_all_airports (Table_hash_airports *thap)
}
}
}
}
}
}
int
is_empty_airlines
(
Table_hash_airlines
thal
)
{
for
(
int
i
=
0
;
i
<
AIRLINE_SIZE_TABLE
;
i
++
)
{
if
(
thal
.
tab_airlines
[
i
]
!=
NULL
)
{
return
1
;
}
}
return
0
;
}
int
is_empty_airports
(
Table_hash_airports
thap
)
{
for
(
int
i
=
0
;
i
<
AIRPORT_SIZE_TABLE
;
i
++
)
{
if
(
thap
.
tab_airports
[
i
]
!=
NULL
)
{
return
1
;
}
}
return
0
;
}
This diff is collapsed.
Click to expand it.
initializeData.h
+
4
−
0
View file @
acd4778e
...
@@ -114,3 +114,7 @@ int hash_function_airport (char *);
...
@@ -114,3 +114,7 @@ int hash_function_airport (char *);
void
free_all_airlines
(
Table_hash_airlines
*
);
void
free_all_airlines
(
Table_hash_airlines
*
);
void
free_all_airports
(
Table_hash_airports
*
);
void
free_all_airports
(
Table_hash_airports
*
);
int
is_empty_airlines
(
Table_hash_airlines
);
int
is_empty_airports
(
Table_hash_airports
);
This diff is collapsed.
Click to expand it.
main.c
+
123
−
106
View file @
acd4778e
...
@@ -26,11 +26,16 @@ int main ()
...
@@ -26,11 +26,16 @@ int main ()
load_airports
(
&
thap
,
airport_file
);
load_airports
(
&
thap
,
airport_file
);
}
}
if
(
flights_file
!=
NULL
)
if
(
flights_file
!=
NULL
&&
(
is_empty_airlines
(
thal
)
==
1
&&
is_empty_airports
(
thap
)
==
1
)
)
{
{
load_flights
(
&
thal
,
&
thap
,
flights_file
);
load_flights
(
&
thal
,
&
thap
,
flights_file
);
}
}
if
(
is_empty_airlines
(
thal
)
==
0
||
is_empty_airports
(
thap
)
==
0
)
{
printf
(
"Chargement des fichiers impossible, veuillez vérifier les fichiers !
\n
"
);
}
else
{
printf
(
"Chargement terminé !
\n
"
);
printf
(
"Chargement terminé !
\n
"
);
char
*
requetes
=
NULL
;
char
*
requetes
=
NULL
;
...
@@ -45,7 +50,8 @@ int main ()
...
@@ -45,7 +50,8 @@ int main ()
while
(
getline
(
&
requetes
,
&
len
,
stdin
)
!=
-
1
)
while
(
getline
(
&
requetes
,
&
len
,
stdin
)
!=
-
1
)
{
{
commande
=
strsep
(
&
requetes
,
" "
);
char
*
requetes2
=
requetes
;
commande
=
strsep
(
&
requetes2
,
" "
);
commande
=
strtok
(
commande
,
"
\n
"
);
commande
=
strtok
(
commande
,
"
\n
"
);
if
(
strcmp
(
commande
,
"quit"
)
==
0
)
if
(
strcmp
(
commande
,
"quit"
)
==
0
)
{
{
...
@@ -53,24 +59,24 @@ int main ()
...
@@ -53,24 +59,24 @@ int main ()
}
}
else
if
(
strcmp
(
commande
,
"show-airports"
)
==
0
)
else
if
(
strcmp
(
commande
,
"show-airports"
)
==
0
)
{
{
airline_id
=
strsep
(
&
requetes
,
"
\n
"
);
airline_id
=
strsep
(
&
requetes
2
,
"
\n
"
);
printf
(
"> Resultat de la requete %s %s :
\n
"
,
commande
,
airline_id
);
printf
(
"> Resultat de la requete %s %s :
\n
"
,
commande
,
airline_id
);
printf
(
"
\n
"
);
printf
(
"
\n
"
);
show_airports
(
airline_id
,
thal
,
thap
);
show_airports
(
airline_id
,
thal
,
thap
);
}
}
else
if
(
strcmp
(
commande
,
"show-airlines"
)
==
0
)
else
if
(
strcmp
(
commande
,
"show-airlines"
)
==
0
)
{
{
airport_id1
=
strsep
(
&
requetes
,
"
\n
"
);
airport_id1
=
strsep
(
&
requetes
2
,
"
\n
"
);
printf
(
"> Resultat de la requete %s %s :
\n
"
,
commande
,
airport_id1
);
printf
(
"> Resultat de la requete %s %s :
\n
"
,
commande
,
airport_id1
);
printf
(
"
\n
"
);
printf
(
"
\n
"
);
show_airlines
(
airport_id1
,
thal
,
thap
);
show_airlines
(
airport_id1
,
thal
,
thap
);
}
}
else
if
(
strcmp
(
commande
,
"show-flights"
)
==
0
)
else
if
(
strcmp
(
commande
,
"show-flights"
)
==
0
)
{
{
airport_id1
=
strsep
(
&
requetes
,
"
\n
"
);
airport_id1
=
strsep
(
&
requetes
2
,
"
\n
"
);
date
=
strsep
(
&
requetes
,
"
\n
"
);
date
=
strsep
(
&
requetes
2
,
"
\n
"
);
time
=
strsep
(
&
requetes
,
"
\n
"
);
time
=
strsep
(
&
requetes
2
,
"
\n
"
);
limit
=
strsep
(
&
requetes
,
"
\n
"
);
limit
=
strsep
(
&
requetes
2
,
"
\n
"
);
if
(
limit
==
NULL
)
if
(
limit
==
NULL
)
{
{
...
@@ -114,7 +120,7 @@ int main ()
...
@@ -114,7 +120,7 @@ int main ()
}
}
else
if
(
strcmp
(
commande
,
"delayed-airline"
)
==
0
)
else
if
(
strcmp
(
commande
,
"delayed-airline"
)
==
0
)
{
{
airline_id
=
strsep
(
&
requetes
,
"
\n
"
);
airline_id
=
strsep
(
&
requetes
2
,
"
\n
"
);
printf
(
"> Resultat de la requete %s %s :
\n
"
,
commande
,
airline_id
);
printf
(
"> Resultat de la requete %s %s :
\n
"
,
commande
,
airline_id
);
printf
(
"
\n
"
);
printf
(
"
\n
"
);
...
@@ -122,7 +128,7 @@ int main ()
...
@@ -122,7 +128,7 @@ int main ()
}
}
else
if
(
strcmp
(
commande
,
"most-delayed-airlines-at-airport"
)
==
0
)
else
if
(
strcmp
(
commande
,
"most-delayed-airlines-at-airport"
)
==
0
)
{
{
airport_id1
=
strsep
(
&
requetes
,
"
\n
"
);
airport_id1
=
strsep
(
&
requetes
2
,
"
\n
"
);
printf
(
"> Resultat de la requete %s %s :
\n
"
,
commande
,
airport_id1
);
printf
(
"> Resultat de la requete %s %s :
\n
"
,
commande
,
airport_id1
);
printf
(
"
\n
"
);
printf
(
"
\n
"
);
...
@@ -130,7 +136,7 @@ int main ()
...
@@ -130,7 +136,7 @@ int main ()
}
}
else
if
(
strcmp
(
commande
,
"changed-flights"
)
==
0
)
else
if
(
strcmp
(
commande
,
"changed-flights"
)
==
0
)
{
{
date
=
strsep
(
&
requetes
,
"
\n
"
);
date
=
strsep
(
&
requetes
2
,
"
\n
"
);
printf
(
"> Resultat de la requete %s %s :
\n
"
,
commande
,
date
);
printf
(
"> Resultat de la requete %s %s :
\n
"
,
commande
,
date
);
printf
(
"
\n
"
);
printf
(
"
\n
"
);
...
@@ -138,8 +144,8 @@ int main ()
...
@@ -138,8 +144,8 @@ int main ()
}
}
else
if
(
strcmp
(
commande
,
"avg-flight-duration"
)
==
0
)
else
if
(
strcmp
(
commande
,
"avg-flight-duration"
)
==
0
)
{
{
airport_id1
=
strsep
(
&
requetes
,
"
\n
"
);
airport_id1
=
strsep
(
&
requetes
2
,
"
\n
"
);
airport_id2
=
strsep
(
&
requetes
,
"
\n
"
);
airport_id2
=
strsep
(
&
requetes
2
,
"
\n
"
);
printf
(
"> Resultat de la requete %s %s %s :
\n
"
,
commande
,
airport_id1
,
airport_id2
);
printf
(
"> Resultat de la requete %s %s %s :
\n
"
,
commande
,
airport_id1
,
airport_id2
);
printf
(
"
\n
"
);
printf
(
"
\n
"
);
...
@@ -156,6 +162,17 @@ int main ()
...
@@ -156,6 +162,17 @@ int main ()
free_all_airlines
(
&
thal
);
free_all_airlines
(
&
thal
);
free_all_airports
(
&
thap
);
free_all_airports
(
&
thap
);
free
(
requetes
);
}
if
(
is_empty_airlines
(
thal
)
==
1
)
{
free_all_airlines
(
&
thal
);
}
if
(
is_empty_airports
(
thap
)
==
1
)
{
free_all_airports
(
&
thap
);
}
fclose
(
airline_file
);
fclose
(
airline_file
);
fclose
(
airport_file
);
fclose
(
airport_file
);
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment