#include <stdio.h>
#include <stdlib.h>
#include <string.h>
void my_strcat(char **str, char **buf)
{
char *ptr;
int n;
int len;
/* 終端の\nを消す */
if (len) {
ptr = *str + len - 1;
if (*ptr == '\n') {
*ptr = '\0';
}
}
if (len) {
ptr = *buf + len - 1;
if (*ptr == '\n') {
*ptr = '\0';
}
}
/* strとbuf分の領域確保 */
ptr
= (char *) realloc(*str
, n
+ 1); if (ptr == NULL) {
/* exit();するのでfree不要
free(*str);
free(*buf);
*/
}
*str = ptr;
/* bufをstrに結合する */
if (n) {
}
return;
}
int main(void)
{
int n;
char *str, *buf;
/* 確保・初期化 */
if (NULL
== (str
= (char *) malloc(30 * sizeof(char)))) { }
if (NULL
== (buf
= (char *) malloc(30 * sizeof(char)))) { }
*str = '\0';
/* 入力、連結 */
for (n = 1;; ++n) {
printf("input string_%d :", n
); if (strcmp(buf
, "quit\n") == 0) { /* quitと入力されたらループを抜ける */
break;
}
my_strcat(&str, &buf);
}
/* 表示 */
/* 終了 */
return 0;
}
I2luY2x1ZGUgPHN0ZGlvLmg+CiNpbmNsdWRlIDxzdGRsaWIuaD4KI2luY2x1ZGUgPHN0cmluZy5oPgoKdm9pZCBteV9zdHJjYXQoY2hhciAqKnN0ciwgY2hhciAqKmJ1ZikKewogICAgY2hhciAqcHRyOwogICAgaW50IG47CiAgICBpbnQgbGVuOwoKICAgIC8qIOe1guerr+OBrlxu44KS5raI44GZICovCiAgICBsZW4gPSBzdHJsZW4oKnN0cik7CiAgICBpZiAobGVuKSB7CiAgICAgICAgcHRyID0gKnN0ciArIGxlbiAtIDE7CiAgICAgICAgaWYgKCpwdHIgPT0gJ1xuJykgewogICAgICAgICAgICAqcHRyID0gJ1wwJzsKICAgICAgICB9CiAgICB9CiAgICBsZW4gPSBzdHJsZW4oKmJ1Zik7CiAgICBpZiAobGVuKSB7CiAgICAgICAgcHRyID0gKmJ1ZiArIGxlbiAtIDE7CiAgICAgICAgaWYgKCpwdHIgPT0gJ1xuJykgewogICAgICAgICAgICAqcHRyID0gJ1wwJzsKICAgICAgICB9CiAgICB9CgogICAgLyogc3Ry44GoYnVm5YiG44Gu6aCY5Z+f56K65L+dICovCiAgICBuID0gc3RybGVuKCpzdHIpICsgc3RybGVuKCpidWYpOwogICAgcHRyID0gKGNoYXIgKikgcmVhbGxvYygqc3RyLCBuICsgMSk7CiAgICBpZiAocHRyID09IE5VTEwpIHsKICAgICAgICAvKiBleGl0KCk744GZ44KL44Gu44GnZnJlZeS4jeimgQogICAgICAgICAgIGZyZWUoKnN0cik7CiAgICAgICAgICAgZnJlZSgqYnVmKTsKICAgICAgICAgKi8KICAgICAgICBleGl0KDEpOwogICAgfQogICAgKnN0ciA9IHB0cjsKCiAgICAvKiBidWbjgpJzdHLjgavntZDlkIjjgZnjgosgKi8KICAgIGlmIChuKSB7CiAgICAgICAgc3RyY2F0KCpzdHIsICpidWYpOwogICAgfQoKICAgIHJldHVybjsKfQoKaW50IG1haW4odm9pZCkKewogICAgaW50IG47CiAgICBjaGFyICpzdHIsICpidWY7CgogICAgLyog56K65L+d44O75Yid5pyf5YyWICovCiAgICBpZiAoTlVMTCA9PSAoc3RyID0gKGNoYXIgKikgbWFsbG9jKDMwICogc2l6ZW9mKGNoYXIpKSkpIHsKICAgICAgICBleGl0KDEpOwogICAgfQogICAgaWYgKE5VTEwgPT0gKGJ1ZiA9IChjaGFyICopIG1hbGxvYygzMCAqIHNpemVvZihjaGFyKSkpKSB7CiAgICAgICAgZXhpdCgxKTsKICAgIH0KICAgICpzdHIgPSAnXDAnOwoKICAgIC8qIOWFpeWKm+OAgemAo+e1kCAqLwogICAgZm9yIChuID0gMTs7ICsrbikgewogICAgICAgIHByaW50ZigiaW5wdXQgc3RyaW5nXyVkIDoiLCBuKTsKICAgICAgICBmZ2V0cyhidWYsIDMwLCBzdGRpbik7CiAgICAgICAgaWYgKHN0cmNtcChidWYsICJxdWl0XG4iKSA9PSAwKSB7CiAgICAgICAgICAgIC8qIHF1aXTjgajlhaXlipvjgZXjgozjgZ/jgonjg6vjg7zjg5fjgpLmipzjgZHjgosgKi8KICAgICAgICAgICAgYnJlYWs7CiAgICAgICAgfQogICAgICAgIG15X3N0cmNhdCgmc3RyLCAmYnVmKTsKICAgIH0KCiAgICAvKiDooajnpLogKi8KICAgIHByaW50Zigic3RyID0gJXNcbiIsIHN0cik7CgogICAgLyog57WC5LqGICovCiAgICBmcmVlKHN0cik7CiAgICBmcmVlKGJ1Zik7CiAgICByZXR1cm4gMDsKfQo=
MQoyMgozMzMKNDQ0NAo1NTU1NQpMMTZfMTExMTIyMjIzMzMzCkwyOV8xMTExMjIyMjMzMzM0NDQ0NTU1NTY2NjZACkwzMF8xMTExMjIyMjMzMzM0NDQ0NTU1NTY2NjZ4QApMMzFfMTExMTIyMjIzMzMzNDQ0NDU1NTU2NjY2eHlACkwzMl8xMTExMjIyMjMzMzM0NDQ0NTU1NTY2NjZ4eXpACkwzNl9BQUFBQkJCQkNDQ0NERERERUVFRUZGRkZHR0dHSEhISAplbmQKcXVpdAo=
1
22
333
4444
55555
L16_111122223333
L29_111122223333444455556666@
L30_111122223333444455556666x@
L31_111122223333444455556666xy@
L32_111122223333444455556666xyz@
L36_AAAABBBBCCCCDDDDEEEEFFFFGGGGHHHH
end
quit