Copying input to output K&R there is no output

This is a discussion on Copying input to output K&R there is no output within the C Programming forums, part of the General Programming Boards category; Code: #include <stdio.h> /* copy input to output; 1st version */ main() { int c; c = getchar (); while ...

  1. #1
    Registered User
    Join Date
    Jan 2013
    Posts
    25

    Copying input to output K&R there is no output

    Code:
    #include <stdio.h>
    /* copy input to output; 1st version */
    main()
    {
    	int c;
    	c = getchar();
    	while (c != EOF) {
    putchar(c);
    		c = getchar();
    	}
    }
    there is no output and no errors at all what would be wrong ?

  2. #2
    Registered User
    Join Date
    Jun 2005
    Posts
    6,679
    getchar() buffers input, and waits until a newline is encountered, before returning the first character typed.

    The net effect is that it will appear as if your program waits for a line before echoing that line.
    Right 98% of the time, and don't care about the other 3%.

    If I seem grumpy or unhelpful in reply to you, or tell you you need to demonstrate more effort before you can expect help, it is likely you deserve it. Suck it up, Sunshine, and read this, this, and this before posting again.

  3. #3
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,855
    What do you mean "no output"

    Did you type anything in?
    Code:
    $ gcc bar.c
    $ ./a.out 
    hello world
    hello world
    hey
    hey
    it works
    it works
    Blue is what I typed, the rest is what the program printed.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.
    I support http://www.ukip.org/ as the first necessary step to a free Europe.

  4. #4
    Registered User
    Join Date
    Jan 2013
    Posts
    25
    I totally misunderstood copying input to output, I thought it would print out the code.
    Thanks you Salem and grumpy!

  5. #5
    Registered User
    Join Date
    Jun 2005
    Posts
    6,679
    What? You thought that code was a quine????? Not even close.
    Right 98% of the time, and don't care about the other 3%.

    If I seem grumpy or unhelpful in reply to you, or tell you you need to demonstrate more effort before you can expect help, it is likely you deserve it. Suck it up, Sunshine, and read this, this, and this before posting again.

  6. #6
    Registered User
    Join Date
    Jan 2013
    Posts
    25
    Quote Originally Posted by grumpy View Post
    What? You thought that code was a quine????? Not even close.
    Oh! you called that quine. Another one got learned thanks!

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 1
    Last Post: 09-24-2009, 02:28 AM
  2. Input/Output
    By Soul.India in forum C Programming
    Replies: 1
    Last Post: 10-30-2003, 05:39 AM
  3. copying input to output
    By kermit in forum C Programming
    Replies: 15
    Last Post: 08-09-2003, 09:57 PM
  4. output as input
    By DDC in forum Linux Programming
    Replies: 3
    Last Post: 02-23-2003, 07:59 AM
  5. Input/Output
    By PaulMelia in forum C Programming
    Replies: 3
    Last Post: 12-02-2001, 08:13 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21