#include <stdio.h>
#include <stdlib.h>
/* 構造体型の宣言 */
typedef struct Test {
int aaaaa;
int bbbbb;
struct Test *next;
} Test;
int main(void) {
Test *prev, *now; /* 構造体を繋ぐ時に使うポインタ */
Test *hyouji; /* 表示に使うポインタ */
Test *p; /* 解放時に使うポインタ */
/* 零番目の構造体(中身は無し) */
Test *first = (Test *)malloc(sizeof(Test));
first->next = NULL;
prev = first;
/* 一番目の構造体 */
now = (Test *)malloc(sizeof(Test));
now->aaaaa = 11;
now->bbbbb = 12;
now->next = NULL;
first->next = now;
prev = now;
/* 二番目の構造体 */
now = (Test *)malloc(sizeof(Test));
now->aaaaa = 21;
now->bbbbb = 22;
now->next = NULL;
prev->next = now;
prev = now;
/* 三番目の構造体 */
now = (Test *)malloc(sizeof(Test));
now->aaaaa = 31;
now->bbbbb = 32;
now->next = NULL;
prev->next = now;
prev = now;
printf("零番目のデータ next%p\n", first->next);
hyouji = first->next;
printf("一番目のデータ aaaaa:%d bbbbb:%d next%p\n", hyouji->aaaaa, hyouji->bbbbb ,hyouji->next);
hyouji = hyouji->next;
printf("二番目のデータ aaaaa:%d bbbbb:%d next%p\n", hyouji->aaaaa, hyouji->bbbbb ,hyouji->next);
hyouji = hyouji->next;
printf("三番目のデータ aaaaa:%d bbbbb:%d next%p\n", hyouji->aaaaa, hyouji->bbbbb ,hyouji->next);
/* 領域の開放 */
p = first;
while (p != NULL) {
now = p->next;
free(p);
p = now;
}
return 0;
}