1

Cygwin64ビット

コンパイルするコマンド:

gcc hello.c -o hello -ansi -pedantic-errors

実行するコマンド

./hello

こんにちはC

#include<stdio.h>
int main() {
    /*setbuf(stdout, 0);        I KNOW THIS WILL WORK IF ADDED, it is a solution, but I want to know why line break itself is not working*/
    printf("hello world!\n");
    printf("hello world again!\r\n");
    /*fflush(stdout);           without fflush, the above strings are not showing*/

    while(1)
    {
    }
}

質問:

  1. 端末に時間内に文字列を表示させるために、すべての printf の後に fflush したくないのですが、どうすればよいですか?

    答え: setbuf(stdout, 0);

  2. 多くの投稿で改行が問題を解決すると指摘されているにもかかわらず、私の場合、「\n」または「\r\n」が機能しないのはなぜですか?

  3. cygwin の端末が通常の Linux の端末と動作が異なるというのは本当ですか? Linux をインストールしていないので、誰かテストしてくれませんか?

  4. または、より一般的な質問をさせてください。どの種類の端末で、「新しい行がフラッシュを強制する」という文が真ですか?

ありがとう

4

4 に答える 4

1

私はcgywinについて何も知りません。しかし、ここでは Linux でテストを行います。

以下のコードを試して、次のようにコンパイルします: gcc -std=c90 filename.c

fflush なし ループの前にすべての単語を出力するので、改行がバッファをフラッシュすると思います! それはただ働く!

SUSE gcc を使用しています。

#include<stdio.h>
int main() {
    /*setbuf(stdout, 0);        I KNOW THIS WILL WORK IF ADDED, it is a solution, but I want to know why line break itself is not working*/
    printf("hello world!\n"); /*without fflush, not shown*/
    printf("hello world again!\r\n"); /*without fflush, not shown*/
  /* fflush(stdout);*/

    while(1)
    {
    }
}
于 2013-08-01T06:04:15.177 に答える