Skip to content
Snippets Groups Projects
Commit 946cdda0 authored by jason.disivuil's avatar jason.disivuil
Browse files

improvements, pb ex1 et ex4

parent e2e866bb
No related branches found
No related tags found
No related merge requests found
*.o *.o
exercice ex1/ex1
\ No newline at end of file ex2/ex2
ex3/ex3
ex4/ex4
\ No newline at end of file
...@@ -3,5 +3,11 @@ ...@@ -3,5 +3,11 @@
## Objectif ## Objectif
Avoir la note la plus élevée possible. Avoir la note la plus élevée possible.
## Mon ressenti
* Exercice 1:
* Exercice 2:
* Exercice 3:
* Exercice 4:
## Auteur ## Auteur
Jason Di Sivuilu Jason Di Sivuilu
\ No newline at end of file
File deleted
...@@ -86,6 +86,28 @@ void list_union(Liste *l_to_fill, Liste *l_to_free){ ...@@ -86,6 +86,28 @@ void list_union(Liste *l_to_fill, Liste *l_to_free){
} }
} }
void delete_doublons(Liste *l){
if(l == NULL){
exit(EXIT_FAILURE);
}
Element *e_actuel = l->premier;
while (e_actuel != NULL)
{
Element *e_actuel2 = e_actuel->suivant;
while (e_actuel2 != NULL)
{
if(e_actuel->valeur == e_actuel2->valeur){
Element *e_to_delete = e_actuel2;
e_actuel2 = e_actuel2->suivant;
free(e_to_delete);
}
e_actuel2 = e_actuel2->suivant;
}
e_actuel = e_actuel->suivant;
}
}
int main(){ int main(){
int lenght1 = 0, lenght2 = 0; int lenght1 = 0, lenght2 = 0;
...@@ -115,17 +137,15 @@ int main(){ ...@@ -115,17 +137,15 @@ int main(){
list_push(l2, tab2[i]); list_push(l2, tab2[i]);
} }
list_union(l1, l2);
display_list(l1);
printf("L'intersection vaut : ");
list_union(l1, l2);
delete_doublons(l1);
// réunion des deux liste en une
// supprime les doublons
// tri dans l'ordre
// TRIER LA LISTE - PLUS QUE CA ET C'EST OK
display_list(l1);
free(tab); free(tab);
free(tab2); free(tab2);
destroy_list(l1); destroy_list(l1);
......
exercice: ex2.o ex2: ex2.o
gcc ex2.o -o exercice -pedantic -fsanitize=address gcc ex2.o -o ex2 -pedantic -fsanitize=address
ex2.o : ex2.c ex2.o : ex2.c
gcc -c ex2.c -Wall -Wextra -pedantic -fsanitize=address gcc -c ex2.c -Wall -Wextra -pedantic -fsanitize=address
clean: clean:
rm -f ex2.o exercice rm -f ex2.o ex2
\ No newline at end of file \ No newline at end of file
#include <stdio.h>
#include <stdlib.h>
int main(){ int main(){
printf("Chaine 1: ");
char * s1 = malloc(100 * sizeof(char));
scanf("%s", s1);
printf("Chaine 2: ");
char * s2 = malloc(100 * sizeof(char));
scanf("%s", s2);
// chaine qui prend les 2 premières
char * s3 = malloc(200 * sizeof(char));
int i = 0;
int j = 0;
// tant qu'on est pas à la fin des fins
while (s1[i] != '\0' || s2[j] != '\0'){
if (s1[i] != '\0'){ // si s1 n'est pas fini
s3[i+j] = s1[i];
i++;
}
if (s2[j] != '\0'){ // si s2 n'est pas fini
s3[i+j] = s2[j];
j++;
}
}
s3[i+j] = '\0';
printf("Chaine de sortie: %s\n", s3);
// libération mémoire
free(s1);
free(s2);
free(s3);
return 0; return 0;
} }
\ No newline at end of file
exercice: ex3.o exercice: ex3.o
gcc ex3.o -o exercice -pedantic -fsanitize=address gcc ex3.o -o exercice -Wall -Wextra -pedantic -fsanitize=address
ex3.o : ex3.c ex3.o : ex3.c
gcc -c ex3.c -Wall -Wextra -pedantic -fsanitize=address gcc -c ex3.c -Wall -Wextra -pedantic -fsanitize=address
......
exercice: ex4.o ex4: ex4.o
gcc ex4.o -o exercice -pedantic -fsanitize=address gcc ex4.o -o ex4 -pedantic -fsanitize=address -Wall -Wextra
ex4.o : ex4.c ex4.o : ex4.c
gcc -c ex4.c -Wall -Wextra -pedantic -fsanitize=address gcc -c ex4.c -Wall -Wextra -pedantic -fsanitize=address
clean: clean:
rm -f ex4.o exercice rm -f ex4.o ex4
\ No newline at end of file \ No newline at end of file
#include <stdio.h> #include <stdio.h>
#include <stdlib.h> #include <stdlib.h>
void table(int nb){
int i = 12;
if(i == 0){
// ?
} else {
printf("%d * %d = %d\n", nb, i, nb * i);
i = i--;
// il faut rappeler la fonction
// mais je n'arrive pas a le faire sans
// que i ne redémarre pas à 12...
}
}
int main(){ int main(){
int i = 0; int i = 0;
printf("Entier: "); printf("Entier: ");
scanf("%d", i); scanf("%d", &i);
table(i);
return 0; return 0;
} }
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment