Find the answer to your Linux question:
Results 1 to 5 of 5
Hi, simple question, i just installed redhat 8.0 and wrote a quick c program to test. int main(){ printf("hello"); } compiles fine but when i do ./a.out in the terminal ...
Enjoy an ad free experience by logging in. Not a member yet? Register.
  1. #1
    Just Joined!
    Join Date
    Jan 2003
    Posts
    8

    no output in terminal window


    Hi, simple question, i just installed redhat 8.0 and wrote a quick c program to test.

    int main(){
    printf("hello");
    }
    compiles fine
    but when i do ./a.out in the terminal i dont see hello, anyone help with this?

    thanks

    Auto

  2. #2
    Linux Guru
    Join Date
    Oct 2001
    Location
    Täby, Sweden
    Posts
    7,578
    It might be some buffering settings (or curor relocation by bash). Do printf("hello\n"); instead (which is what I guess that you want anyway).

  3. #3
    Linux User
    Join Date
    Jul 2002
    Location
    Daytona Beach, FL
    Posts
    487
    i believe you are right with the buffer - when you don't use the \n you are not forcing the buffer to be flushed, so if you exit the program before it gets around to flushing the buffer - data bye bye (I remember my C teacher ranting about this while Sam and I wrote entire programs in #defines)
    majorwoo

    Quiet brain, or I\'ll stab you with a Q-tip.

  4. $spacer_open
    $spacer_close
  5. #4
    Linux Guru
    Join Date
    Oct 2001
    Location
    Täby, Sweden
    Posts
    7,578
    No, that's not it. I don't know about other libc implementations, but at least glibc fcloses std{in,out,err} after main exits, which causes them to be flushed. I would rather guess that it's due to some strange terminal buffering settings. On the other hand, I just tried the exact same program, and it worked, getting a new shell prompt directly after (no LF) the hello.

  6. #5
    Linux User
    Join Date
    Jul 2002
    Location
    Daytona Beach, FL
    Posts
    487
    i dont know that i am confortable blaming it on the terminal, but you are right about glibc flushing the buffer for you... and i gues that doesn't leave me much else to blame
    majorwoo

    Quiet brain, or I\'ll stab you with a Q-tip.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •