inf301-debug_segfaults/poly/src/exemple.c

32 lines
644 B
C

#include <stdlib.h>
#include <stdio.h>
struct liste {
struct liste* suivant;
int valeur;
};
typedef struct liste liste_t;
liste_t* alloc_cell(int val) {
liste_t* cell = malloc(sizeof(liste_t));
cell->valeur = val;
cell->suivant = NULL;
return cell;
}
void afficher_liste(liste_t* tete, int taille) {
liste_t* cur = tete;
for(int pos=0; pos < taille; ++pos) {
printf("%d\n", cur->valeur);
cur = cur->suivant;
}
}
int main(int argc, char** argv) {
int n = atoi(argv[1]);
liste_t* tete = alloc_cell(1);
tete->suivant = alloc_cell(2);
afficher_liste(tete, n);
return 0;
}