init projet

This commit is contained in:
2024-10-06 15:32:20 +02:00
commit d449d4b10a
84 changed files with 13546 additions and 0 deletions

BIN
tp1/Sources-TD1/._.ccls Normal file

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

12
tp1/Sources-TD1/.ccls Normal file
View File

@@ -0,0 +1,12 @@
gcc-13
%c -std=std2x
%c -Wall
%c -Wextra
%c -pedantic
%c -Wshadow
%c -Wpointer-arith
%c -Wcast-qual
%c -Wstrict-prototypes
%c -Wmissing-prototypes
%c -Wno-gnu-zero-variadic-macro-arguments
%c -I/opt/homebrew/include/

View File

@@ -0,0 +1,2 @@
((c-mode . ((+format-with . uncrustify))))
;; ((c-mode . ((+format-with . clang-format))))

3643
tp1/Sources-TD1/.uncrustify Normal file

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,55 @@
#include <stdio.h>
void echange_1(int x, int y) {
int tmp;
tmp = x;
x = y;
y = tmp;
}
void echange_2(int *x, int *y) {
int *tmp;
tmp = x;
x = y;
y = tmp;
}
void echange_3(int *x, int *y) {
int tmp;
tmp = *x;
*x = *y;
*y = tmp;
}
void echange_4(int *x, int *y) {
int *tmp;
*tmp = *x;
*x = *y;
*y = *tmp;
}
// Expliquer de façon détaillée et justifiée ce qu'on obtient à l'exécution.
int main(void) {
int a = 1, b = 2;
echange_1(a, b);
printf("a = %d, b = %d\n", a, b);
a = 1, b = 2;
echange_2(&a, &b);
printf("a = %d, b = %d\n", a, b);
a = 1, b = 2;
echange_3(&a, &b);
printf("a = %d, b = %d\n", a, b);
a = 1, b = 2;
echange_4(&a, &b);
printf("a = %d, b = %d\n", a, b);
return 0;
}

View File

@@ -0,0 +1,15 @@
#include <stdio.h>
#include <stdlib.h>
int main(void) {
int a = 1, b = 2, c = 3, d = 4;
int *p1 = &a, *p2 = &b, *p3 = &c, *p4 = &d, *p5;
p5 = p3;
*p3 = *p2;
*p2 = *p5;
*p4 = *p1;
*p1 = *p4;
printf("a, b ,c and d are equal to: %d, %d, %d and %d\n", a, b, c, d);
exit(EXIT_SUCCESS);
}

View File

@@ -0,0 +1,33 @@
#include <stdio.h>
#include <stdlib.h>
int *x1[1], *x2[1], y[1], z[1];
void f(int **p) {
**p = 2;
*p = y;
**p = 3;
p = x2;
*p = z;
**p = 4;
// Fin de f
}
int main(void) {
int **p, ***q, **r, *s, t;
p = x1;
*p = &t;
**p = 1;
q = &p;
r = p;
s = *p;
printf("%d %d %d %d %d %d \n", ***q, **p, **r, *s, *z, t);
f(p);
printf("%d %d %d %d %d %d \n", ***q, **p, **r, *s, *z, t);
exit(EXIT_SUCCESS);
}

View File

@@ -0,0 +1,20 @@
#include <stdio.h>
#include <stdlib.h>
int main(void) {
int a = 1, b = 2, c = 3, d = 4;
int *p1 = &a, **p2 = &p1, *p3 = &c, *p4 = &b, **p5 = &p3, *p6 = &d;
*p3 = **p2 + 6;
*p2 = p3;
*p1 = *p4 * 5;
p5 = &p6;
**p5 = **p5 + **p2;
*p4 = *p3 + 14;
*p5 = p1;
**p2 = 1 + **p2;
**p5 = **p5 * **p2;
printf("a, b ,c and d are equal to: %d, %d, %d and %d\n", a, b, c, d);
return 1;
}

View File

@@ -0,0 +1,39 @@
#include <stdio.h>
#include <stdlib.h>
int x1, y1, y2, z1, z2;
int *px1 = &x1,
*py1 = &y1, *py2 = &y2,
*pz1 = &z1, *pz2 = &z2;
void aux(int **p, int ***q)
{
**p = 2;
***q = 99;
*p = pz1;
**p = 12;
p = &py2;
*q = &px1;
**p = 4;
***q = 42;
}
int main(void)
{
int **p, **q, ***r, s, *t;
p = &py1;
q = &px1;
r = &q;
*p = &s;
**q = 1;
**p = 34;
***r = 76;
t = **r;
r = &p;
aux(p, &q);
printf("%d %d %d %d %d \n",
**q, **p, ***r, s, *t);
return 1;
}

View File

@@ -0,0 +1,39 @@
#include <stdio.h>
#include <stdlib.h>
void foo(int **);
int main(void);
int somme(void);
int resultat = 0;
void foo(int **p) {
resultat++;
*p = &resultat;
main();
return;
}
int m;
int *p[5] = {&m, &m, &m, &m, &m};
int somme(void) {
int i;
int s = 0;
for (i = 0; i < 5; i++)
s += *p[i];
return s;
}
int main(void) {
static int n;
if (n == 5)
printf("%d\n", somme());
else
foo(p + n++);
exit(EXIT_SUCCESS);
}

View File

@@ -0,0 +1,39 @@
#include <stdio.h>
#include <stdlib.h>
void foo(int *p);
int somme(void);
int main(void);
int resultat = 0;
void foo(int *p) {
resultat++;
p = &resultat;
main();
return;
}
int m;
int *p[5] = {&m, &m, &m, &m, &m};
int somme(void) {
int i;
int s = 0;
for (i = 0; i < 5; i++)
s += *p[i];
return s;
}
int main(void) {
static int n;
if (n == 5)
printf("%d\n", somme());
else
foo(p[n++]);
exit(EXIT_SUCCESS);
}

View File

@@ -0,0 +1,39 @@
#include <stdio.h>
#include <stdlib.h>
void foo(int **p);
int somme(void);
int main(void);
int resultat = 0;
void foo(int **p) {
int resultbis = ++resultat;
*p = &resultbis;
main();
return;
}
int m;
int *p[5] = {&m, &m, &m, &m, &m};
int somme(void) {
int i;
int s = 0;
for (i = 0; i < 5; i++)
s += *p[i];
return s;
}
int main(void) {
static int n;
if (n == 5)
printf("%d\n", somme());
else
foo(p + n++);
exit(EXIT_SUCCESS);
}

View File

@@ -0,0 +1,45 @@
#include <stdio.h>
#include <stdlib.h>
void foo(int **p);
int somme(void);
int main(void);
int resultat = 0;
void foo(int **p) {
int resultbis = ++resultat;
*p = &resultbis;
main();
return;
}
int m;
int *p[5] = {&m, &m, &m, &m, &m};
int somme(void) {
int i;
int s = 0;
for (i = 0; i < 5; i++) {
printf("%d\n", *p[i]);
s += *p[i];
}
return s;
}
int main(void) {
static int n;
int m = n;
if (n != 5) {
foo(p + (m = n++));
if (m == 0)
printf("%d\n", somme());
else
return 0;
}
exit(EXIT_SUCCESS);
}