c - C90 printf with \n or \r\n not working in cygwin; but fflush(stdout); works fine. why? -


cygwin64 bit

command compile:

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

command run

./hello 

hello.c

#include<stdio.h> int main() {     /*setbuf(stdout, 0);        know work if added, solution, want know why line break not working*/     printf("hello world!\n");     printf("hello world again!\r\n");     /*fflush(stdout);           without fflush, above strings not showing*/      while(1)     {     } } 

questions:

  1. i don't want fflush after every printf let terminal show string in time, how?

    answer: setbuf(stdout, 0);

  2. why "\n" or "\r\n" not working in case considering lots of posts pointed out line break fix problem?

  3. is true cygwin's terminal behaves differently normal linux's terminal? since don't have linux installed, give test me?

  4. or let me ask more general question: on kinds of terminals, sentence "a new line force flush" true?

thanks

that program works me under 32-bit cygwin. specifically, when compile , execute program:

#include<stdio.h> int main() {     /*setbuf(stdout, 0);        know work if added, solution, want know why line break not working*/     printf("hello world!\n");     printf("hello world again!\r\n");     /*fflush(stdout);           without fflush, above strings not showing*/      while(1)     {     } } 

it produces output:

hello world! hello world again! 

and hangs until kill ctrl-c.

i same behavior invoking program bash under windows console, mintty, , xterm (i doubt terminal make difference).

i'm using 32-bit cygwin under 64-bit windows 7. you're using 64-bit cygwin, just announced few days ago; haven't tried yet.

i suspect issue 64-bit vs. 32-bit cygwin. suggest post cygwin mailing list.

here's cleaned-up version of program should exhibit same issue (please verify comments correct):

#include <stdio.h> int main(void) {     /* adding setbuf(stdout, 0) here makes output appear */     printf("hello world!\n");     /* adding fflush(stdout) here makes output appear */     while(1) {         /* nothing */     } } 

Comments

Popular posts from this blog

basic authentication with http post params android -

vb.net - Virtual Keyboard commands -

How to get multiresult with multicondition in Sql Server -