Thread: my output is weird

  1. #1
    Registered User
    Join Date
    Sep 2005

    my output is weird


    I have this as my standard input:

    Buffalo Bill's
    who used to
    ride a watersmooth-silver
    and break onetwothreefourfive pigeonsjustlikethat

    ( one tab on 3rd and 4th lines, 3 tabs on 5th line)

    and my cod is this:

    #include <stdio.h>
    #include <stdlib.h>
    File* fptr;
    int c;
    fptr = fopen( "poetery.out", "w");
    while ( getchar() != EOF )
         if( ( c = getchar() ) != EOF )
         fputc( c, fptr );
    return EXIT_SUCCESS;
    output is:

    ufl ilsdfnt h sdt
    rd aesot-ivr tlinadbekoewtreoriepgosutieht

    can anybody explain why it does this? it's an excersize from a book, question and solution, but it doesn't explain why, and I can't figure out what is happening.

    Thank you

  2. #2
    Registered User
    Join Date
    Aug 2005
    each time getchar() is called it reads one character from the keyboard. Your program is calling that function twice, tossing away the character the first time. Try this fix
    int c;
    while ( (c = getchar()) != EOF )
         fputc( c, fptr );
    Last edited by Ancient Dragon; 11-10-2005 at 02:13 PM.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Weird output of scanf and printf.
    By omnificient in forum C Programming
    Replies: 2
    Last Post: 12-05-2007, 01:28 PM
  2. Output an array in a textbox
    By Diablo02 in forum C# Programming
    Replies: 5
    Last Post: 10-18-2007, 03:56 AM
  3. Connecting input iterator to output iterator
    By QuestionC in forum C++ Programming
    Replies: 2
    Last Post: 04-10-2007, 02:18 AM
  4. Trying to store system(command) Output
    By punxworm in forum C++ Programming
    Replies: 5
    Last Post: 04-20-2005, 06:46 PM
  5. Output problems with structures
    By Gkitty in forum C Programming
    Replies: 1
    Last Post: 12-16-2002, 05:27 AM