文字列が配列に格納される順序を逆にして、最後の文字列が新しい配列の最初になるようにします。これまでのところ、データを取得して最初の配列に格納していますが、そこで立ち往生しています。文字列自体ではなく、文字列の順序を逆にしたいだけです。
入力例:
here is a sample
line two of test
出力:
line two of test
here is a sample
これまでのところ、入力を最初の配列に格納します。
// Accept user input until hit EOF.
while (( c = getc(stdin) ) != EOF) {
if(input != NULL) {
int c = EOF;
int i = 0;
// Accept user input until hit EOF.
while (( c = getc(stdin) ) != EOF) {
input[i++] = (char)c;
input[i++] = (char)c;
// If reached maximize size, realloc size.
if (c == '\n') {
input[i]='\0';
}
if (i == current_size) {
current_size = i + len_max;
input = realloc(input, current_size);
}
}
input[i] = '\0';
}