Entrainements + fin TP structures
This commit is contained in:
0
DEV1.1/TP25/TP25_reponses.txt
Normal file
0
DEV1.1/TP25/TP25_reponses.txt
Normal file
28
DEV1.1/TP25/test.c
Normal file
28
DEV1.1/TP25/test.c
Normal file
@@ -0,0 +1,28 @@
|
||||
# include <stdio.h>
|
||||
# include <stdlib.h>
|
||||
|
||||
struct maillon {
|
||||
int valeur;
|
||||
struct maillon* suivant;
|
||||
};
|
||||
|
||||
|
||||
void creation_liste(struct maillon* liste) {
|
||||
int i;
|
||||
liste->valeur = (rand() % 888) + 111;
|
||||
for (i = 0; i != 10; i++) {
|
||||
struct maillon* prochain = (struct maillon*) malloc(sizeof(struct maillon*));
|
||||
if (prochain == NULL) {
|
||||
printf("Erreur d'allocation mémoire.\n");
|
||||
}
|
||||
prochain->valeur = (rand() % 888) + 111;
|
||||
liste->suivant = prochain;
|
||||
}
|
||||
}
|
||||
|
||||
int main(void) {
|
||||
struct maillon* liste = NULL;
|
||||
srand(time(NULL));
|
||||
creation_liste(liste);
|
||||
return EXIT_SUCCESS;
|
||||
}
|
Reference in New Issue
Block a user