私はいくつかの文を挿入するプログラムを作成しており、プログラムはそれらを順番に出力します。私はプログラムを終了しましたが、私がそれを実行すると、配列に入力された文字が表示されたり正しく格納されず、結果として完全な文の代わりにランダムな文字が得られるようです。プログラムは2d配列の文字をcに格納しません
char ch;
int i,j,k;
int nothing = 0;
int count = 1;
char lines[5][256];
int length[256];
int main() {
printf("Please insert up to a max of 5 lines of text (Press enter to go to next line and twice enter to stop the program):\n");
i = 0;
while (i<5){
j = 0;
ch = getche();
if (ch == '\r'){
if(i!= 0){
break;
}
printf("You have not inserted anything, please insert a line:");
i=-1;
}
if(ch != '\r'){
lines[i][j]=ch;
while (ch!='\r'){
ch = getche();
lines[i][j] = ch;
j++;
}
}
printf("\n");
i++;
}
for (k=i ; k > 0; k--){
printf("\tphrase %i :", count);
for (j =0 ; j <= length[k]; j++){
printf("%c",lines[j][k]);
}
count++;
printf("\n");
}
return 0;
}
文字を正しく表示するにはどうすればよいですか?どんな助けもありがとう、ありがとう!
コードをフォーマットしてください。私は "}"末尾を教えてくれません – Simon
実際の出力対期待出力を表示します –
'getche()'を使う特別な理由はありますか?どのプラットフォームの下でこれをコンパイルしましたか? – roelofs