#include<stdio.h>
#include<string.h>
#include<stdlib.h>
struct data{
char key;
struct data *next;
};
void print_stack_list(struct data *top);
int main()
{
struct data *top, *cur;
cur = top;
top = (struct data*)malloc(sizeof(struct data));
if(top == NULL){printf("メモりが確保できませんでした。\n"); return 1; }
top->key = 'a';
top->next = (struct data*)malloc(sizeof(struct data));
if(top->next == NULL){printf("メモりが確保できませんでした。\n"); return 1; }
top = top->next;
top->key = 'b';
top->next = (struct data*)malloc(sizeof(struct data));
if(top->next == NULL){printf("メモりが確保できませんでした。\n");
return 1; }
top = top->next;
top->key = 'c';
top->next = NULL;
top = cur;
print_stack_list(top);
return 0;
}
void print_stack_list(struct data *top)
{
while(top !=NULL)
{
printf("%c\n",top->key);
top = top->next;
}
}
I2luY2x1ZGU8c3RkaW8uaD4KI2luY2x1ZGU8c3RyaW5nLmg+CiNpbmNsdWRlPHN0ZGxpYi5oPgpzdHJ1Y3QgZGF0YXsKICBjaGFyIGtleTsKICBzdHJ1Y3QgZGF0YSAqbmV4dDsKfTsKCnZvaWQgcHJpbnRfc3RhY2tfbGlzdChzdHJ1Y3QgZGF0YSAqdG9wKTsKICAKCmludCBtYWluKCkKewogCiAgc3RydWN0IGRhdGEgKnRvcCwgKmN1cjsKIAogCiAgY3VyID0gdG9wOwogdG9wID0gKHN0cnVjdCBkYXRhKiltYWxsb2Moc2l6ZW9mKHN0cnVjdCBkYXRhKSk7CiAgaWYodG9wID09IE5VTEwpe3ByaW50Zigi44Oh44Oi44KK44GM56K65L+d44Gn44GN44G+44Gb44KT44Gn44GX44Gf44CCXG4iKTsgcmV0dXJuIDE7ICAgICB9CiAgdG9wLT5rZXkgPSAnYSc7CiAgdG9wLT5uZXh0ID0gKHN0cnVjdCBkYXRhKiltYWxsb2Moc2l6ZW9mKHN0cnVjdCBkYXRhKSk7CmlmKHRvcC0+bmV4dCA9PSBOVUxMKXtwcmludGYoIuODoeODouOCiuOBjOeiuuS/neOBp+OBjeOBvuOBm+OCk+OBp+OBl+OBn+OA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