私はC言語の本を読んでいましたが、次のコードに固執しました... Cコードを示したように、for()ループを使用して文字を取得しています。また、forループを使用して画面に文字を出力するのと同じ方法です...ユーザーがエンターを押すと、ループが終了し、画面に出力するために使用される他の for() ループが i 変数の値を使用します。しかし、画面上の結果は逆です。どうすればそれを整理できますか?
#include <string.h>
#include <stdio.h>
int main()
{
int i;
char msg[25];
printf_s("Type up to 25 characters then press Enter..\n");
for (i = 0; i < 25; i++)
{
msg[i] = getchar();// Gets a character at a time
if (msg[i] == '\n'){
i--;
break;// quits if users presses the Enter
}
}putchar('\n');
for (; i >= 0 ; i--)
{
putchar(msg[i]);// Prints a character at a time
}putchar('\n');/*There is something wrong because it revers the input */
getchar();
return 0;