#include <stdio.h>
#include <stdlib.h>
#include <string.h>
struct data_list {
struct data_list *next;
char data[];
};
int main(int argc, char **argv)
{
int res;
char buf[1024];
struct data_list data_list = { 0 }, *p, *pp;
int l;
fputs("文字列を入力してください。ctrl-dで終了:\n", stderr
); for (;;) {
if (fgets(buf
, sizeof(buf
) - 1, stdin
) == NULL
) break;
for (p = &data_list; p->next != NULL; p = p->next);
p
->next
= malloc(sizeof(data_list
) + l
+ 1); if (p->next == NULL) {
res = 1;
goto PG_END;
}
p->next->next = NULL;
}
for (p = data_list.next; p != NULL; p = p->next)
res = 0;
PG_END:;
// free
p = data_list.next;
while (NULL != p) {
pp = p->next;
p = pp;
}
return res;
}
I2luY2x1ZGUgPHN0ZGlvLmg+CiNpbmNsdWRlIDxzdGRsaWIuaD4KI2luY2x1ZGUgPHN0cmluZy5oPgoKc3RydWN0IGRhdGFfbGlzdCB7CiAgICBzdHJ1Y3QgZGF0YV9saXN0ICpuZXh0OwogICAgY2hhciBkYXRhW107Cn07CgppbnQgbWFpbihpbnQgYXJnYywgY2hhciAqKmFyZ3YpCnsKICAgIGludCByZXM7CiAgICBjaGFyIGJ1ZlsxMDI0XTsKICAgIHN0cnVjdCBkYXRhX2xpc3QgZGF0YV9saXN0ID0geyAwIH0sICpwLCAqcHA7CiAgICBpbnQgbDsKCiAgICBmcHV0cygi5paH5a2X5YiX44KS5YWl5Yqb44GX44Gm44GP44Gg44GV44GE44CCY3RybC1k44Gn57WC5LqGOlxuIiwgc3RkZXJyKTsKICAgIGZvciAoOzspIHsKICAgICAgICBmcHV0cygiPyAiLCBzdGRlcnIpOwogICAgICAgIGlmIChmZ2V0cyhidWYsIHNpemVvZihidWYpIC0gMSwgc3RkaW4pID09IE5VTEwpCiAgICAgICAgICAgIGJyZWFrOwogICAgICAgIGwgPSBzdHJsZW4oYnVmKTsKICAgICAgICBmb3IgKHAgPSAmZGF0YV9saXN0OyBwLT5uZXh0ICE9IE5VTEw7IHAgPSBwLT5uZXh0KTsKICAgICAgICBwLT5uZXh0ID0gbWFsbG9jKHNpemVvZihkYXRhX2xpc3QpICsgbCArIDEpOwogICAgICAgIGlmIChwLT5uZXh0ID09IE5VTEwpIHsKICAgICAgICAgICAgcGVycm9yKCJNYWxsb2PjgavlpLHmlZfjgZfjgb7jgZfjgZ8iKTsKICAgICAgICAgICAgcmVzID0gMTsKICAgICAgICAgICAgZ290byBQR19FTkQ7CiAgICAgICAgfQogICAgICAgIHAtPm5leHQtPm5leHQgPSBOVUxMOwogICAgICAgIHN0cmNweShwLT5uZXh0LT5kYXRhLCBidWYpOwogICAgfQogICAgcHV0YygnXG4nLCBzdGRlcnIpOwoKICAgIGZvciAocCA9IGRhdGFfbGlzdC5uZXh0OyBwICE9IE5VTEw7IHAgPSBwLT5uZXh0KQogICAgICAgIGZwdXRzKHAtPmRhdGEsIHN0ZG91dCk7CgogICAgcmVzID0gMDsKICBQR19FTkQ6OwogICAgLy8gZnJlZQogICAgcCA9IGRhdGFfbGlzdC5uZXh0OwogICAgd2hpbGUgKE5VTEwgIT0gcCkgewogICAgICAgIHBwID0gcC0+bmV4dDsKICAgICAgICBmcmVlKHApOwogICAgICAgIHAgPSBwcDsKICAgIH0KICAgIHJldHVybiByZXM7Cn0=