#include <stdio.h>
#include <stdlib.h>
#include <string.h>
void my_strcat(char **str, char **buf)
{
char *ptr;
if (len) {
ptr = *str + len - 1;
if (*ptr == '\n') {
*ptr = '\0';
}
}
ptr
= (char *) realloc(*str
, n
+ 1); /*strとbuf分の領域確保 */ if (ptr == NULL) {
}
*str = ptr;
strcat(*str
, *buf
); /*bufをstrに結合する */ return;
}
int main(void)
{
int n = 2;
char *str, *buf;
str
= (char *) malloc(30 * sizeof(char)); buf
= (char *) malloc(30 * sizeof(char)); for (n = 1;; ++n) {
printf("input string_%d :", n
); if (strcmp(buf
, "quit\n") == 0) { break;
} /*quitと入力されたらループを抜ける */
my_strcat(&str, &buf);
}
return 0;
}
I2luY2x1ZGUgPHN0ZGlvLmg+CiNpbmNsdWRlIDxzdGRsaWIuaD4KI2luY2x1ZGUgPHN0cmluZy5oPgoKdm9pZCBteV9zdHJjYXQoY2hhciAqKnN0ciwgY2hhciAqKmJ1ZikKewogICAgY2hhciAqcHRyOwogICAgaW50IG4gPSBzdHJsZW4oKnN0cikgKyBzdHJsZW4oKmJ1Zik7CiAgICBpbnQgbGVuID0gc3RybGVuKCpzdHIpOwogICAgaWYgKGxlbikgewogICAgICAgIHB0ciA9ICpzdHIgKyBsZW4gLSAxOwogICAgICAgIGlmICgqcHRyID09ICdcbicpIHsKICAgICAgICAgICAgKnB0ciA9ICdcMCc7CiAgICAgICAgfQogICAgfQogICAgcHRyID0gKGNoYXIgKikgcmVhbGxvYygqc3RyLCBuICsgMSk7ICAgIC8qc3Ry44GoYnVm5YiG44Gu6aCY5Z+f56K65L+dICovCiAgICBpZiAocHRyID09IE5VTEwpIHsKICAgICAgICBmcmVlKCpzdHIpOwogICAgICAgIGZyZWUoKmJ1Zik7CiAgICAgICAgZXhpdCgxKTsKICAgIH0KICAgICpzdHIgPSBwdHI7CiAgICBzdHJjYXQoKnN0ciwgKmJ1Zik7ICAgICAgICAgLypidWbjgpJzdHLjgavntZDlkIjjgZnjgosgKi8KICAgIHJldHVybjsKfQoKaW50IG1haW4odm9pZCkKewogICAgaW50IG4gPSAyOwogICAgY2hhciAqc3RyLCAqYnVmOwogICAgc3RyID0gKGNoYXIgKikgbWFsbG9jKDMwICogc2l6ZW9mKGNoYXIpKTsKICAgIGJ1ZiA9IChjaGFyICopIG1hbGxvYygzMCAqIHNpemVvZihjaGFyKSk7CiAgICBmb3IgKG4gPSAxOzsgKytuKSB7CiAgICAgICAgcHJpbnRmKCJpbnB1dCBzdHJpbmdfJWQgOiIsIG4pOwogICAgICAgIGZnZXRzKGJ1ZiwgMzAsIHN0ZGluKTsKICAgICAgICBpZiAoc3RyY21wKGJ1ZiwgInF1aXRcbiIpID09IDApIHsKICAgICAgICAgICAgYnJlYWs7CiAgICAgICAgfSAgICAgICAgICAgICAgICAgICAgICAgLypxdWl044Go5YWl5Yqb44GV44KM44Gf44KJ44Or44O844OX44KS5oqc44GR44KLICovCiAgICAgICAgbXlfc3RyY2F0KCZzdHIsICZidWYpOwogICAgfQogICAgcHJpbnRmKCJzdHIgPSAlcyIsIHN0cik7CiAgICBmcmVlKHN0cik7CiAgICBmcmVlKGJ1Zik7CiAgICByZXR1cm4gMDsKfQo=
MQoyMgozMzMKNDQ0NAo1NTU1NQpMMTZfMTExMTIyMjIzMzMzCkwyOV8xMTExMjIyMjMzMzM0NDQ0NTU1NTY2NjZACkwzMF8xMTExMjIyMjMzMzM0NDQ0NTU1NTY2NjZ4QApMMzFfMTExMTIyMjIzMzMzNDQ0NDU1NTU2NjY2eHlACkwzMl8xMTExMjIyMjMzMzM0NDQ0NTU1NTY2NjZ4eXpACkwzNl9BQUFBQkJCQkNDQ0NERERERUVFRUZGRkZHR0dHSEhISAplbmQKcXVpdAo=
1
22
333
4444
55555
L16_111122223333
L29_111122223333444455556666@
L30_111122223333444455556666x@
L31_111122223333444455556666xy@
L32_111122223333444455556666xyz@
L36_AAAABBBBCCCCDDDDEEEEFFFFGGGGHHHH
end
quit