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

46
tp2/main.c Normal file
View File

@@ -0,0 +1,46 @@
#include "compare.h"
#include "genprint.h"
int main(int argc, char *argv[]) {
int i;
type_t t;
int ntype = NUMTYPES; // nombre de types possibles
int n = (argc >= 2) ? atoi(argv[1]) : -1; // n = nombre d'éléments
const char *s = (argc >= 3) ? argv[2] : type[INT]; // t = type des éléments
for (t = 0; t < ntype; t++)
if (!strcmp(s, type[2 * t]))
break; // type trouvé !
if (n < 0 || t == ntype) { // erreur
printf("\n Usage: %s n [t]", argv[0]);
printf("\n Ex.: %s 10 int\n\n", argv[0]);
printf(" n = number of random elements\n");
printf(" t = type of elements & fcmp():\n\n");
for (t = 0; t < ntype; t++) {
printf(" '%s' ", type[2 * t]);
// rule(12 - strlen(type[2 * t]), ".");
printf(" %s\n", type[2 * t + 1]);
}
printf("\n");
exit(1);
}
unsigned seed = time(NULL) % 1000;
srandom(seed);
printf("\nseed: %u\n", seed); // pour rejouer la même chose au cas où
void *T = malloc(n * size[t]); // tableau initial
printf("Tableau avec %i elements de type '%s'\n", n, type[2 * t]);
printf("(%s)\n", type[2 * t + 1]);
// affichage et création de T[]
printf("input array: ");
for (i = 0; i < n; i++) {
init(t, T, i);
print(t, T, i);
}
printf("\n\n");
return 0;
}